I have an update for my website and some Javascript files are changed. But some customers are still getting the old Javascript file and not the new one. They can remove their temporary internet files, but that's not what I want.
Is there something in IIS6 that I can use?
Change the link to the .js file - add a parameter .js?ver=1.0, for example.
Every time you change the .js file, change the parameter - this will ensure clients will be getting the latest version.
You can use "cache busting". A simple solution is to append a version number in the query string, eg: script.js?v=1.1.
Another solution is to dynamically calculate a checksum or hash of the .js file that gets automatically appended to the query string, so everytime you modify the contents of the .js file, a new checksum/hash is generated and appended to the query string.
Related
I'm working on a thin client web project - front end part only - with visual studio. I need to have the js and css file versioning within the htmls to remove the browser caching issue. Is there any way that I can achieve this with VS? ( I'm using SVN for the code repo )
If I understand it right, you are trying to burst the cache or invalidate the cache by trying to have new version of file every time the client requests the page from server. You can either append a query string to the URL of the CSS/javscript file links embedded in your HTML like :
<script src="//xyz.com/abc.js?12345"></script>
You can generate the query string dynamically using current date time or using some random number generation and add it as query string to the URL.
Or if you wish to maintain the files with different version numbers in the source code, something like abc.v1.js and abc.v2.js, you can use gulp or grunt task to generate the file and update the html with the version link
Finally found it. You can add a ?v=3.4.5.2 like versioning to the file and then replace the matching regex with the update revision num + timestamp by a before build script
I am administrating a web page were we have an HTML dokument linking to PDF-files. The PDF-files gets updated from time to time, but we don't want to change the file names. This means that the users get old cached copies of the files, and have to refresh the files manually in order to get the newest file.
I added the following code to the links:
onClick="this.href=this.href.split('?')[0]+'?'+new Date().getTime()">
This solved the problem were the users got old files, but introduced a problem were the user needs to load PDFs even though they have not been updated. This causes more server load, and longer wait times for the users. Is it possible to get a similar code were the script checks a hash or the file size of the target file and adds that to the URL behind the questionmark? If this is possible I would overcome all my problems.
I dont know where you got access to but i assume you can use php.
So you should append an md5 (generated by md5_file()) as parameter to your string. The parameter will only change, if you upload a new pdf (mtime() will have the same effect)
I have this problem with my web server will not reload our javascript files when we eg overwrite with a new one, if for example, we have made a mistake in the previous file.
If we just throw a file on top of the same name, update the file does not, we will have to create a new file with a different name.
Anyone have a solution to it?
It has nothing to do with Ubuntu nor JavaScript, but browser (or server?) caching.
The simplest way to force the non-cached version to be used is to add a version to your file when you update it, using a query string like this:
<script src="myScript.js?v=2"></script>
If you wish to always force the non-cached version, you can use the timestamp instead and get something like:
<script src="myScript.js?t=1407845240"></script>
Browsers will see these are different files and always load them from scratch. Both t and v are custom variables, so you can use whatever you want there - it's important that their value changes with each new version of the file (or automatic, if you're using the timestamp method).
Ctrl+F5 in your browser to refresh the page will force it to get your new JS file.
So I changed some jquery on a page in my application and it works fine etc.
But I just noticed that when I push the code to a different server and run the page on that server I need to hit ctrl + f5 to see the changes reflected. Is there a way when doing a code push to clear the cache on that page / javascript so it loads the latest version not the cached version.
on your referenced javascript file you can add a querystring, like:
<script src="/scripts/myfile.js?v=1" type="text/javascript"></script>
whenever you change the text in the file update the query string.
You need to take a look at your js files content expiry.
One way to solve this problem is to append a dummy query string parameter to all your *.js urls and set it to the build number of your app or file modified time.
/Scripts/file.js?v=1.0.12345.0
This will ensure that each build will use new urls and you can set their content expiry to never.
I'm using CKEditor which is a multi-file library so the main js file calls other js and css files. I'm noticing that after the main file is called, additional files have a ?t=CODE added to them, so something like this, but the actual files don't have that extra ?t=B49E5BQ at the end.
http://site.com/ckeditor/config.js?t=B49E5BQ
http://site.com/ckeditor/extra.js?t=B49E5BQ
What's the point of this
P.S. Please feel free to add additional tags, because I'm not sure about this one.
This sort of trailing data is sometimes put into URLs for resources files like scripts/stylesheets so as to prevent caching of resources across re-deployments.
Whenever you change a resource, you change the code in HTML files/templates which require that resource, so that clients re-request the resource from the server the next time they load the page.
I would guess that the URL parameter is added to bypass any caching mechanisms. When a client sees the same URL with a different query parameter, that usually means the client can't use the cached version of the resource (in this case a JS file) and go to the server to fetch the latest version.
In HTTP, if a URL is the same in every way except for the URL parameters, a client can not assume that those files/resources are the same resulting object.
Which means:
http://site.com/ckeditor/config.js?t=B49E5BQ
is not the same as:
http://site.com/ckeditor/config.js?t=1234
It must be there to prevent caching.
I do this occasionally for images and script files. In my case, it's a meaningless argument (usually datetime) that just forces the browser to fetch a new copy every time.
If the parameter keeps changing, those files won't be cached on the client side.
Often this is easier than say, changing the name of the file to include a version number (jquery-1.6.2.js works nicely, but do you want to rename config.js to config-1.0.js, -2.0, etc. every time you make a change?
Like all the other answers, this simply forces the browser to grab the latest version when the querystring (?t=B49E5BQ) is changed. In our case, we simply add the date (?06022011).