This link has been bookmarked by 102 people . It was first bookmarked on 08 Jan 2008, by lilin_fr.
-
10 May 12
-
26 Mar 12
-
30 Jan 12
-
29 Dec 11
-
01 Oct 11
-
28 Sep 11
-
27 Sep 11
-
08 Aug 11
-
11 Apr 11
-
28 Mar 11
-
07 Feb 11
-
28 Oct 10
-
15 Sep 10
-
14 Sep 10
-
08 Sep 10
-
26 Jul 10
-
17 Jul 10
-
26 Apr 10
-
10 Mar 10
-
09 Nov 09
-
25 May 09
-
20 May 09
-
15 May 09
-
12 May 09
-
18 Mar 09
-
20 Dec 08
-
03 Dec 08
-
30 Sep 08
Eamonn O'Brien-StrainNice implementation in PHP. I might try to implement the same in Java. Perhaps as a taglib.
-
02 Sep 08
-
22 Aug 08
Paul J. Martinezntry was posted 7 months ago and was filed under Notebooks.
You can follow comment -
08 Jul 08
-
13 Jun 08
-
30 May 08
-
26 May 08
-
30 Apr 08
-
25 Mar 08
-
21 Mar 08
-
04 Mar 08
-
31 Jan 08
-
28 Jan 08
-
17 Jan 08
-
16 Jan 08
-
13 Jan 08
-
12 Jan 08
-
11 Jan 08
-
10 Jan 08
-
09 Jan 08
Rafa BayonaGestionar fàcilment les versions de scripts i fulles d'estil amb Mod_Rewrite
-
08 Jan 08
-
mandarineWe wrote a tiny PHP function that would look at the last modified date of the file and automatically rewrite the url with that unix timestamp as the version number.
-
-
set an Expires header on your static files
-
Keep in mind, if you use a far future Expires header you have to change the component’s filename whenever the component changes. At Yahoo! we often make this step part of the build process: a version number is embedded in the component’s filename, for example, yahoo_2.0.6.js.
-
The first thing we did was set up some mod rewrite rules to allow version numbers in our file names. In our .htaccess file, we added the following lines:
#Rules for Versioned Static Files RewriteRule ^(scripts|css)/(.+)\.(.+)\.(js|css)$ $1/$2.$4 [L] -
What this does is quietly redirects any files located in our
\scripts\or\css\folders with version numbers in between the file name and the extension back to just the filename and extension. For example, I could now rewrite the url /css/structure.css as /css/structure.1234.css and Apache would see those as the exact same files. We only do versioned files for our JavaScript and CSS, but you could easily adapt the rule for images as well, like so:#Rules for Versioned Static Files RewriteRule ^(scripts|css|images)/(.+)\.(.+)\.(js|css|jpg|gif|png)$ $1/$2.$4 [L]Once that was in place, we wrote a tiny PHP function that would look at the last modified date of the file and automatically rewrite the url with that unix timestamp as the version number. Here’s that PHP function:
<?php function autoVer($url){ $path = pathinfo($url); $ver = '.'.filemtime($_SERVER['DOCUMENT_ROOT'].$url).'.'; echo $path['dirname'].'/'.str_replace('.', $ver, $path['basename']); } ?>Then, in our PHP documents we would include the function and then call it like so in the HTML markup:
include($_SERVER['DOCUMENT_ROOT'].'/path/to/autoVer.php'); <link rel="stylesheet" href="<?php autoVer('/css/structure.css'); ?>" type="text/css" /> <script type="text/javascript" src="<?php autoVer('/scripts/prototype.js'); ?>"></script>When the pages load, our script would request the file modified timestamp and insert them in like this:
<link rel="stylesheet" href="/css/structure.1194900443.css" type="text/css" /> <script type="text/javascript" src="/scripts/prototype.1197993206.js"></script>It’s a great little system and required very little effort on our end and resulted in a noticeably faster browsing experience for our clients that frequented certain pages often, because their browsers were taking full advantage of their primed caches rather than calling our servers every time they loaded a page. The best part is that when we make a change to a CSS or JavaScript file, we don’t have to worry about tracking or managing version numbers or multiple files.
-
-
yatil2kWe, of course, didn’t have a built in build process that added the version number to our static files. Obviously, we weren’t interested in changing version numbers by hand or having tons of different versioned files lying around in our SVN depository.
js javascript css file version expires header php htaccess yslow
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.