Uploaded image for project: '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
    • Status: Resolved
    • Priority: 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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                stachoo Stanisław Osiński
                Reporter:
                stachoo 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