iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
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

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-09-2007, 06:51 PM
WebProWorld Member
 
Join Date: Dec 2006
Location: Indianapolis
Posts: 41
modrewrite RepRank 0
Lightbulb mod_rewrite Version Control for frequently updated files

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]
The XHTML
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>
More robust/complex example
Code:
RewriteEngine On
RewriteBase /
RewriteRule ^([cij]+)(/?[a-z]*)/([a-z]+)-([0-9]+)\.([a-z]+)$ /$1$2/$3.$5 [L]
The XHTML
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>
Read the Original Article to learn more and combine this method with htaccess caching
__________________
de // AskApache.com blog
Reply With Quote
  #2 (permalink)  
Old 07-11-2007, 08:14 AM
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Cornwall, UK
Posts: 972
speed RepRank 1
Default Re: mod_rewrite Version Control for frequently updated files

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.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 11:52 PM.



Search Engine Optimization by vBSEO 3.3.0