2

I want to run some custom scripts on one of my pages. No problem, just put in the script tag...

<script type="text/javascript" src="scripts/init.js"></script>

and I add my init.js to SitePages/scripts/ and then my script runs fine the first time around. Only problem is, I can make changes to the script and save them, but the website will still use the original init.js, and it is impossible to get the new script to run under the same name, as the original init.js is for whatever reason still stored on the sharepoint site. I know this because the first init.js had an alert('Init ran!');, but then when I made changes I changed the alert to alert('Updated init ran!') but when I save the file it still displays an alert with the first "Init ran!", so it's obviously not updating. Why does this happen and how can I fix it?

4

This is simply browser caching, and it is pretty predominant in SPO.

Some things to try:

  • Hard refresh your page (Shift + F5)
  • Use a private browser tab
  • Update your js file reference with ?rev=1 to force a download of the file. Increment this number every time you make a change to your init.js file.
4

While developing, set your browser to Disabled caching in F12-Developer Tools

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.