|
|
||||||
|
||||||
| Index Link To US Private Messages Archive FAQ RSS | ||||||
| Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome. |
Share Thread: & Tags
|
||||
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Web Developers sometimes use file.ext?v=001 as a version control system so they can force visitors to use an updated file. This is so bad.
Let's look at how we can accomplish the same thing (and much better caching and site speed) using a simple RewriteRule. So I have 2 files to demonstrate. /c/apache.css and /j/apache.js - now I have my htaccess setup so that .js and .css files are cached forever, so what do I do when I make an update to either of those files? I create a RewriteRule in my .htaccess file so that /j/apache-001.js points to /j/apache.js, but the visitors browser only sees /j/apache-001.js, and when I update /j/apache.js, I only have to change the links in my XHTML to /j/apache-002.js and that forces the browser to use the updated file! As long as the HTML isn't being cached too aggressively, this system is great and I use it on all my clients sites. The htaccess Code:
RewriteEngine On RewriteBase / RewriteRule ^j/apache-([0-9]+).js$ /j/apache.js [L] RewriteRule ^c/apache-([0-9]+).css$ /c/apache.css [L] Code:
<link href="http://z.askapache.com/c/apache-004.css" rel="stylesheet" type="text/css" /> <script src="http://z.askapache.com/j/apache-004.js" type="text/javascript"></script> Code:
RewriteEngine On RewriteBase / RewriteRule ^([cij]+)(/?[a-z]*)/([a-z]+)-([0-9]+)\.([a-z]+)$ /$1$2/$3.$5 [L] Code:
<link href="http://z.askapache.com/c/anything-007.css" rel="stylesheet" type="text/css" /> <script src="http://z.askapache.com/j/anything-007.js" type="text/javascript"></script> |
|
|||
|
I agree file.ext?v=001 is not a nice way to control versions as it defeats the browser cache, but I'm not convinced of the value of using mod_rewrite this way.
You have to update all your pages to the new version number anyway so why not simply upload the changed file as apache-002.js etc, and if you are using Dreamweaver for the project then just renaming the file also updates all the links to it which reduces the risk of you missing one. Uploading the files with a version number would save the expense of running mod_rewrite, defeats the browser cache the same way and works on hosts that don't allow mod_rewrite for whatever reason. The only arguments I can think of for using mod_rewrite for this are: a) You don't need to leave the previous version on the server to cater for any clients that still have the HTML cached but not the file in question. b) If you are shipping an application it saves the user having to clean up old versions after an upgrade, but then your application may not work with all hosting providers which is why the parameter based versioning is used/works. Argument a is doubtful as you stated you cache those files forever, therefore if the HTML is cached so should the versioned files. Argument b above can be ignored unless you decide to limit your applications market. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| JBoss Portal updated to version 2.4 | dutter | Web Programming Discussion Forum | 0 | 08-30-2006 01:33 PM |
| Why google results vary so frequently | organic-seo | Google Discussion Forum | 6 | 06-15-2006 05:05 PM |
| Frequently Asked - New Directory | spherica | Link Exchange | 0 | 04-22-2006 11:08 AM |
| Are frequently updated sites spidered more frequently? | johnstexas | Google Discussion Forum | 6 | 03-20-2005 01:12 PM |
| Frequently Asked.info - New Shopping Directory | fathom | Marketing Strategies Discussion Forum | 0 | 03-31-2004 06:23 AM |
|
WebProWorld |
Advertise |
Contact Us |
About |
Forum Rules |
MVP's |
Archive |
Newsletter Archive |
Top |
WebProNews
WebProWorld is an iEntry, Inc. ® site - © 2009 All Rights Reserved Privacy Policy and Legal iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 |