• An alternative would be to add ?version=123 to the end of files, instead of faking a directory.

  • I have some files like scriptaculous.js?load=effects or file.swf?load=some_param and it was simpler for me to fake some directories. If you don’t use such constructs, perhaps the ?version=123 parameter will be easier to use.

  • I like this directory based approach, instead of using a query param), but I think there are a few problems with both of them (assuming that I got right what you said).

    At work I’m using Capistrano for deployment, and Capistrano creates a file called REVISION in which it writes the current revision hash (taken from Git).

    If I’d use this revision number as a directory name under which all the static components will virtually reside, that means on every deployment, all static components will be have to be re-fetched by the browser (and we do a lot of deployments). What I’ve done instead is to write a little PHP script that concatenates and minifies all CSS and JS files at deploy time and writes the string in a new file and names it like all.sha1_hash.js. The sha1_hash is the sha1 checksum of the new concatenated, minified source. Thus, the name of the file only gets modified when the sum of the contents modifies.

    For images, that are not used for styling, I use a subdomain (static) which indeed uses mod_expires, and their expiry date is about 4 months, although I could add more. Actually, CSS and JS files are sent with Expires headers too.

  • Yep, using checksums is another good idea, but it might take a little too long if you have lots of large files that need hashing. Anyway, it’s more a matter of personal convenience, I think that all approaches are good.

  • Adrian

    “Just redirect all the URLs like /static/(number)/css/style.css to point to /static/css/style.css, by adding these 2 lines in the /static/.htaccess file:

    RewriteEngine On
    RewriteRule ^/static/(d+)/(.*)$ $2 [NC,L]

    Actually the rewrite as you wrote it will be from /static/(number)/css/style.css to /css/style.css not /static/css/style.css (also you don’t need to escape forward slashes, this perhaps comes from the fact that you used to use / as a delimiter, but in rewriterules it’s not the case). You should do:

    RewriteRule ^/static/d+/(.*)$ /static/$1 [NC,L]

    or, if you use Apache 2.x, you can use the lookbehind

    RewriteRule (?<=^/static/)d+/(.*)$ $1 [NC,L]

  • Pingback: mod_expires - vBulletin SEO Forums()

Advertisment ad adsense adlogger