SmartSprites
  1. SmartSprites
  2. SMARTSPRITES-41

Sprite image MD5 hash or date should be part of file name rather than a request parameter

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.2.8
    • Labels:
      None

      Description

      Motivation

      As pointed out by Nicolas, when MD5 hash or date is appended as a request parameter (after ? character), proxies may not cache such images. For this reason, a better and recommended approach is to make the MD5 hash or date part of the file name.

      Implementation

      The implementation will introduce a simple variable substitution mechanism to be used in the sprite-image values. These will allow to weave a number of dynamic variables, such as MD5 hash, into the names of sprite images and the paths that reference sprite images in the generated background-image CSS properties.

      The format of the variables will follow Ant's property syntax, i.e. ${variable}. Initially, 3 variables will be resolved:

      • sprite – name of the sprite as declared in the sprite property
      • md5 – MD5 hash of the sprite image
      • date – a string representing current date and time in the YYYYMMDDHHmmssms format

      Additionally, to support a use case where cache busting values are not embedded in sprite names but follow after the ? character, the sprite-image property will allow inserting a query string at the end of the sprite image path. Sprite image file name will be determined by removing everything from the first occurrence of a ? character to the end of the sprite-image property value. The provided query string, with variables resolved, will be copied to the generated background-image CSS properties.

      SmartSprites should issue a warning when:

      • an unsupported variable is referenced
      • variable syntax seems malformed (unbalanced } or { characters)

      Deprecation

      When this feature is implemented, the sprite-image-uid will become deprecated. Until support for sprite-image-uid is removed, it will work as currently specified, ie. append MD5 hash or date at the end of background-image, preceded by a ? character. Additionally, a warning will be issued that sprite-image-uid is deprecated and variables in sprite-image should be used instead.

      The sprite-image-uid will continue to be supported in the 0.2.x and 0.3.x versions, it will be removed in the 0.4.0 of SmartSprites.

      Discussion

      Although more complicated to implement, this design should support both the current and the new image hash use case. Additionally, it will prevent the explosion of new sprite-* properties, allow more flexibility when formatting sprite file names and allow adding further variables in the future. An interesting feature for the future might also be making the sprite-image directive optional and providing a configurable default value for it, e.g. ../img/{sprite}-{hash}.png.

        Issue Links

          Activity

          Hide
          Kevin Vanderbeken added a comment -

          We use request parameters - so this works very well... the option to keep the original could be quite helpful.

          However, having it in the filename should remove the IE6 bug where backgrounds placed on a block anchor element hover state "flash" when hovered over when request parameters are used.

          So again, a parameter to enable or disable would empower people's decisions.
          You make the call

          Show
          Kevin Vanderbeken added a comment - We use request parameters - so this works very well... the option to keep the original could be quite helpful. However, having it in the filename should remove the IE6 bug where backgrounds placed on a block anchor element hover state "flash" when hovered over when request parameters are used. So again, a parameter to enable or disable would empower people's decisions. You make the call
          Hide
          Stanisław Osiński added a comment -

          I've redesigned this area a bit, I hope the new approach will give us more flexibility and open up some possibilities for the future. Please let me know what you think.

          Show
          Stanisław Osiński added a comment - I've redesigned this area a bit, I hope the new approach will give us more flexibility and open up some possibilities for the future. Please let me know what you think.
          Hide
          Stanisław Osiński added a comment -

          Moving out of the 0.2.4 release.

          Show
          Stanisław Osiński added a comment - Moving out of the 0.2.4 release.
          Hide
          Stanisław Osiński added a comment -

          Implemented in trunk.

          The binaries with this feature can be downloaded from:

          http://download.csssprites.org/smartsprites-0.2.8-SNAPSHOT.zip

          Show
          Stanisław Osiński added a comment - Implemented in trunk. The binaries with this feature can be downloaded from: http://download.csssprites.org/smartsprites-0.2.8-SNAPSHOT.zip

            People

            • Assignee:
              Stanisław Osiński
              Reporter:
              Stanisław Osiński
            • Votes:
              3 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 6h
                6h
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 5h 13m Time Not Required
                5h 13m

                  Development