Note that there are some explanatory texts on larger screens.

plurals
  1. POHowto: Javascript files always up-to-date
    primarykey
    data
    text
    <p>I have a .NET web applications which uses a lot of javascript. The .aspx and the .js files go hand-in-hand together. Problem: The .aspx files are always up-to-date on the client (not cached) but the .js files might well be cached. This is even a problem if the files are only cached for one session since users are spending many hours on my site and everytime I update a .aspx/.js pair users are running into a problem. </p> <p>Now, I found a solution but I am not sure if there is perhaps a better solution or if my solution has a performance drawback. </p> <p>This is my solution: </p> <p>.js-References in .aspx: </p> <pre><code>&lt;script type='text/javascript' src='../scripts/&lt;%# GetScriptLastModified("MyScript.js") %&gt;'&gt;&lt;/script&gt; </code></pre> <p>So, the "GetScriptLastModified" will append a ?v= parameter like this:</p> <pre><code>protected string GetScriptLastModified(string FileName) { string File4Info = System.Threading.Thread.GetDomain().BaseDirectory + @"scripts\" + FileName; System.IO.FileInfo fileInfo = new System.IO.FileInfo(File4Info); return FileName + "?v=" + fileInfo.LastWriteTime.GetHashCode().ToString(); } </code></pre> <p>So, the rendered .js-Link would look like this to the client:</p> <pre><code>&lt;script type='text/javascript' src='/scripts/GamesCharts.js?v=1377815076'&gt;&lt;/script&gt; </code></pre> <p>The link will change every time, when I upload a new version and I can be sure that the user immediately gets a new script or image when I change it. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload