3

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.

1
  • A lot of frameworks and such are designed to be able to easily retrieve information from the query string. Other than that I'm not aware of any benefit. Basically more widespread adoption. Commented Jul 22, 2011 at 21:47

3 Answers 3

7

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.

Sign up to request clarification or add additional context in comments.

2 Comments

source control is a good additional perspective on the subject
i agree with your comments on this being related to cache controlling. I am aware of option 2 might have multiple files in source control if not implemented right.
1

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.

Comments

0

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.