JavaScript and possible browser cache issue

I am new to JavaScript and I am having the following problem:

I would write the JS code in a separate file, including the file in the html code. JS code works fine. No problems. I would like to make some changes to the JS code, click update in the browser window, and sometimes a problem occurs. The changes I made to the JS code ruined everything. The code does not work as intended. So I'm starting to look for the problem, but the code is fine. So I clear my browser cache - nothing anyway. I undo changes in the JS code, everything works. I returned the new code - after a few clicks of "update" - suddenly it works. I have a problem with Safari 4, Firefox 2.0. I have not tried another browser.

My question is: do I need to disable browser caching using any JS technique, or just from a browser, or is there another problem? Thanks for your time and help!

+3
source share
4 answers

When you reload / refresh the web page, most time scripts reload from the cache. You can force the browser to reload the external script file (s) by holding the Shift key while pressing the refresh button.

If this does not work, you can check if a proxy exists between you and the web page. If it is a local web page, the toggle button should do the trick.

+3
source

If you are linking to your JS file with a random key that will prevent caching:

eg:

var randomnumber=Math.floor(Math.random()*10000)
var scriptfile='http://www.whatever.com/myjs.js?rnd='+randnumber;

, .

+4

CTRL + F5.

+2

I find when I debug some JS, I just have a url to open javascript in another tab. When I download, I first switch to the tab, click update, and then check the code. This or cache queue in the FireFox WebDeveloper plugin.

+1
source

Source: https://habr.com/ru/post/1705929/


All Articles