简体   繁体   中英

Website serves the old/depreciated version of javascript file instead of the updated one

EDIT: Would my current meta tags be causing the caching issue?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/homepage.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  

I have a website uploaded to the webhost iPower. My HTML pages link an external javascript file(called AppLogic.js). I find when I upload a new version of AppLogic.js to the webhost that the older versions(previously uploaded versions) are served from the server instead of my latest AppLogic.js upload. This happens for about 5mins(sometimes even longer) after I upload a new version of AppLogic.js, after that period of time it then begins serving the correct AppLogic.js file(latest one).

Do you know why this is happening & how I can stop this?

I have a feeling that javascript files are cached in IE, Firefox & that they are not downloading the new file everytime. I am trying to fix bugs that only occur on the actual webpages served from the webhost (the bugs aren't occuring locally) which means I am constantly tweaking my AppLogic.js file then uploading it to the webserver to see if the change fixed a bug. Its slow & annoying without this bloody caching of .js files but with this issue its just god damn stopping me from fixing bugs!

Any advice on what exactly goes wrong & how to fix it would be extremely helpful

All the following things I have tried but don't stop myself getting the wrong .js file:
- I have tried pressing CTRL, SHIFT & DELETE in firefox, then deleting all the history & caches
- Pressing CTRL 12 in IE to open the Developer tools, then selecting cache then selecting always load from server, delete cache, delete domain cookies & all the other ones. This only works sometimes which is dang frustrating.
- Use the program CCleaner to remove all my cookies & other IE cached data. Sometimes works - Restarting my whole laptop. works alot but is ridiculously time consuming

You could alter the way you request the JS file, by adding AppLogic.js?123456789 (where the numbers are time). That way, you force the browser to load the new files at all times!

You can also add the following in ur .htaccess

<FilesMatch "AppLogic.js$">
Header unset Cache-Control
Header unset Expires
Header unset Last-Modified
FileETag None
Header unset Pragma
</FilesMatch>

It wont cache the file for the users ...you could try to add that for a period of time then remove it because you don't want to always serve the file ... we want some CACHE ;)

SiteSafeNL solution works great , try to declare a global variable version and then it get changed on each website update AppLogic.js?v=1.0.0 then on update AppLogic.js?v=1.0.1 etc ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM