views:

30

answers:

3

Hi, we are having MVC web application. some of the code is in javascript. when we deploy any changes to the javascript the changes are not reflected on the client side. We have to ask clients to do CTRL+F5 to get the changes. Is there a standard way of pushing javascript changes to the clientside?

+2  A: 

You can refer to the files with a version, like this:

<script type="text/javascript" src="myScript.js?v=12345"></script>

The number after v represents your build number, so when a new build pushes, they grab the files again. View source on this page to see the same behavior :) This gives you the benefit of allowing the user to cache the files as long as possible (forever), yet still have them automatically grab any update.

Nick Craver
A: 

you can try this meta tags

<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
GerManson
A: 

You're not saying what server-side language your site is in. A nifty trick from the Rails world is to check the "last modified" time of the file, and to add that as a GET parameter to the URL.

In PHP, it would look like this:

<script type="text/javascript" 
        src="script.js?time=<?php echo filemtime("script.js");">

(of course, the path you need to give in the filemtime call will probably need to be an absolute one.)

Pekka