jQuery Script caching on localhost

I have an ASP.NET 3.5 web application written in VS 2010. I have an aspx with a script reference to a .js file that resides in a Scripts folder.

<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="Scripts/HeaderControl.js" type="text/javascript"></script>

Within the .js file I'm using jQuery to do some various operations, one of which was simply a debugging statement that used alert to spit out a value on the page so I could see what it was.

if ($) {
    $(document).ready(function () {
        $("input[id='q']").click(function($e) {
            alert("clicked");
        });
    });
}

This all worked great until I went to remove the debug statement (the alert "clicked"). Upon completely removing it from the .js, I rebuilt the project, hit F5 to run it on my localmachine, but as soon as I clicked upon the input tag above the alert still popped up and said "clicked". I tried one thing after another trying to get the web app to realize that the .js had been changed, but it kept displaying the alert every time that I'd click on the input tag. I finally decided to rename the .js to something completely different, at which time the web app realized that the .js had been changed and it quit displaying the alert when I'd click upon the input tag.

So why was this .js file being cached? It's a very annoying behavior and I'd love to know what exactly was causing it. Any help would be appreciated. Thanks!

EDIT: Browser was IE7. I didn't check to see if it did it in Mozilla as well. Regardless, I've done at least a 100 different .js files and I've never noticed this behavior before. The only difference for me is that this .js is in a web app, whereas usually I'm creating them in ASP.NET web site projects.

Answers


You need to Shift + Refresh, or, just clear your browser's cache.

This is normal behavior:

Javascript and CSS files do not even check for a new version (an If-Modified-Since request) if the old version is still valid according to the cache headers in the response sent the first time.

I believe that if you put in any query string, even just ?, at the end of the url (i.e., Scripts/jquery-1.4.1.min.js?) some browsers (Firefox at least) will change to check for a new version of the file every time like it will for images. This could be useful during development.

Some developers will also append a version to the file (?123) so that they can cause the browser to ignore the cache completely when a new version of a web app is released. I'm not sure how effective this is if you already have a question mark at the end, since it will be looking for an updated version anyway (again, not sure about all browsers).


Need Your Help

Custom taxonomy slug before post name

wordpress permalinks custom-taxonomy

I want that specific custom post url will look like:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.