Web Developers sometimes use file.ext?v=137 as a version control system so they can force visitors to use an updated file. This is terrible. Instead link to apache-003.css and set it to be cached forever. When you change the file you just change the links to apache-004.css.
Raw Speed Benefit
That eliminates millions of bandwidth and resource robbing If-Modified-Since requests.
Renaming links vs. Renaming files
On the server my files are named apache.css and apache.js, but in the html I point to them using the names apache-113.css and apache-113.js, after I change the file I just add 1 to the number, and the new file is cached. They are internally redirected to apache.css and apache.js (invisible to the user) The concept is similar to a “shortcut” in windows or a symlink in BSD. The trick is that I never actually rename the files on the server. I just rename them in the html. That means apache-135.css is served from the file apache.css but the browser/cache only see and know about apache-135.css.
XHTML
NOTE: You can do your own investigating of this sites source code and HTTP headers to see this whole system in action
<link href="http://z.askapache.com/c/apache-113.css" rel="stylesheet" type="text/css" /> <script src="http://z.askapache.com/j/apache-113.js" type="text/javascript"></script>
mod_rewrite code for htaccess or httpd.conf
RewriteEngine On RewriteBase / RewriteRule ^j/apache-([0-9]+)\.js$ /j/apache.js [L] RewriteRule ^c/apache-([0-9]+)\.css$ /c/apache.css [L]
Alternate
RewriteEngine On RewriteBase / RewriteRule ^([cij]+)(/?[a-z]*)/([a-z]+)-([0-9]+)\.([a-z]+)$ /$1$2/$3.$5 [L]
Ideal Caching Scheme
Ok so you want the html to be the only file that isn’t cached without being validated, its simple to setup your own caching scheme.
Cache information for a file with the ?v=foo hack.
This object will be fresh for 1 week. It can be validated with Last-Modified. This object requests that a Cookie be set; this makes it and other pages affected automatically stale; clients must check them upon every request. Because it contains a query (’?') in the URL, many caches will not keep this object.
htaccess apache mod_rewrite rewritecond rewriterule cache version control update
Related Articles
- Speed Tips: Remove Last-Modified Header
- Crazy Cache WordPress Plugin Released
- Speed Up Google Analytics, use local ga.js
- Speed Tips: Add Cache-Control Headers
- Replacing ‘%23′ with ‘#’ in incoming links
- Prevent WP-Cache from Caching index
- Make phpBB SEO friendly with htaccess
- Speed Tips: Add Future Expires Headers