zero7
zero7

Reputation: 1298

js & css versioning

Knowing that I can version js and css files like

Option 1:

myJavaScript.js?v=#myVersionNumber#
myCSS.css?v=#myVersionNumber#

, This will make client to do a conditional GET request and best case scenario get a 304 response. I can eliminate this http request by a different versioning strategy like

Option 2:

myJavaScript.#myVersionNumber#.js
myCSS.#myVersionNumber#.css

I am wondering if there are any good reasons (assuming that both options have the same level of maintainability), that will make me stay with Option1.

Thanks for the help.

Upvotes: 3

Views: 877

Answers (3)

user2822868
user2822868

Reputation:

Here is an article that may help you regarding this issue...

Automatically Version Your CSS and JavaScript Files

This code is in php, and some modifications in .htaccess file of your website, which may need some more attention otherwise your site may breakdown.

Upvotes: 1

jfriend00
jfriend00

Reputation: 708156

Isn't the simplest option myJavascript-1.js ? And, just bump that number in both the filename and the source that loads it every time you rev the file? No query string required. Cache is always defeated when you release a new version.

There are sometimes reasons to leave the old version still available to avoid a client with a cached HTML page ever getting mixed versions of old and new among several different files and this allows both new and old to easily exist in the file system on your server at the same time (if desired).

Upvotes: 0

Kevin Bowersox
Kevin Bowersox

Reputation: 94499

I would argue that your not really versioning as much as controlling caching. With the second approach I would be worried about storing multiple files in the source control systems, when if you stored a single file it will accumulate a history and can be managed easier. You can then release the new file by changing the parameter in your url.

Upvotes: 7

Related Questions