skip to Main Content

I have an embed webpart in sharepoint that showcases part of our available content, it’s an html file that calls a script.js generated by an excel spreadsheet. The list of content changes often enough that multiple updates are pushed every week, often once a day.

Currently, it reads the .js correctly, but, if the file changes, it only reads the file again on a force reload.

I have tried adding the following code to my HTML:
<meta http-equiv="Cache-Control" content="no-cache,no-store, must-revalidate"/>
But it didn’t change my situation.
Is there any way I can make it update without the user force reloading the page?
Ideally, only the HTML file would be edited, because the .js is generated automatically.

2

Answers


  1. Add a random number to the URL if you can.

    Depending on how you generate the url in the first place the syntax may vary but something along the lines of

    let script = document.createElement('script');
    script.src = 'my.js?' + Math.random();
    document.body.append(script);
    

    So make a new script that you always load with this code, referencing to your real script (my.js) and load this script instead from your html file and you should be fine.

    Login or Signup to reply.
  2. you can add a time stamp to the end of the JavaScript file URL to ensure that the browser always loads the latest version of the file.

    <script src="path/to/your-script.js?t=<%= new Date().getTime() %>"></script>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search