How to update javascript file content on the page?

1

I searched the forum and did not find a definitive solution, my problem is with regard to browser cache, when I make a change to a javascript file, my client only receives the updated file after cleaning the cache.

We have already dealt with the code below:

<script src='<%=Page.ResolveClientUrl("~/Scripts/MeuJavaScript.js?sid=" + Session.SessionID) %>

Where we concatenate the user session to the file link, but even then the file remains outdated.

Thank you.

    
asked by anonymous 10.11.2017 / 19:35

1 answer

0

You can configure the browser through the meta tag to not cache your site content, like this:

<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />

Update

You can make an ajax request at the beginning of your script to check the version on your server, so every time it updates you run the command:

window.location.reload(true)

Or send a message to the user informing about the new script.

    
10.11.2017 / 19:58