Javascript stops working and only returns with empty cache?

Asked

Viewed 107 times

0

Lately I have been very angry with Javascript, the reason is that I write my codes and functions in Javascript and they apparently don’t work. Then I need to open the browser in anonymous tab, then they work. Sometimes I need to clear the entire browser cache for the changes I made to the code to work again. There are times that even cleaning the browser cache and opening in anonymous mode the code does not work, then to see it work I need to send it on my server in a testing domain to be able to test it.

Why does this happen? Because every time I change a code in Javascript it never works first and forces me to keep doing all this gambit to make the code work?

When finally I can run a Javascript code after clearing the cache or use in anonymous tab, it remains working for a long time, but according to what I give refresh on the page (to test changes) it stops working again. This worries me, because and if this happens to the user who accesses my site and functions stop working according to the number of hits that it makes on the site?

I declare all scripts at the end of the code before closing body.

  • 2

    The cache issue is not gambiarra, it is the natural behavior of the browser that will help you a lot in production environment. To get around it, you can read Force javascript file update without disabling cache. Now, to know why it stops working after a few hits, you’ll need to post the codes here.

2 answers

1


The browser cache is precisely to optimize a web application, taking advantage of the content of the page so that it is not necessary to reload some resources every time the page is updated. What I suggest for the development environment, would be the use of the browser Chrome. Press F12 to open the window Code Inspection, click on the 3 dots at the top of the window and then click on Settings to open the settings. Check the box Disable cache (while Devtools is open) as in the image below:

DevTools

And whenever you’re developing and testing your code, leave the Code Inspection.

-3

The logical solution is the cache you made on the first load as you might already know. This explains why an update in the code does not run first. I press about 5 or 6 times the F5 to occur the cache update. And so I see my update work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.