Skip to content

Merged JS/CSS improvements #10

Closed
Closed
@colinmollenhour

Description

@colinmollenhour

In Magento 1.x I made some improvements to Mage_Core_Model_Design_Package. Seems like now is a good time to suggest these for 2.0:

  • Cached latest mtime of all files to be merged (I see 2.0 does this, but in a .dat file.. why not the Magento cache?)
  • Added a cache type for said cache records (so that Cache Management can be used to clean just the mtime records without affecting the rest of the cache)
  • Added a separate base url for merged files vs media files. This is because CDNs are generally not reliable and if your merged CSS or JS doesn't load your page is broken. We serve merged files directly and all other media files from a CDN to prevent this.
  • The file names are hashed once for the mtime cache record, but the final merged file name is an MD5 hash which includes these pieces of information which ensures that merged files never need to be purged from an upstream cache or browser:
    • Mage::getBaseUrl('skin') in case the skin url is updated
    • The hash of the file names (re-use mtime cache key)
    • The most recent mtime in case one of the files is updated
    • IMPORTANT: The request protocol (http or https) to prevent browser security warnings on https pages
  • If the file exists ending with -min then this file name is returned instead. This allows use of an external script to minify the JS or CSS whithout overwriting the original file which may be cached upstream before it is minified.
  • Never delete the parent directory of the merged files, just the contents. This way an inotify script can watch the directory and minify files as they are created. Deleting the parent directory breaks the inotify watches.
  • For CSS image url replacement use the real skin base url rather than the web base so skin assets can be served from CDN.

You can see my extended Package.php with these features here: https://gist.github.com/2364485

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions