When executing web pages, the client / browser decides whether it updates the file, such as an image or .css or .js, or if it takes it from the cache.
In the case of the .aspx page, this is decided by the server.
Of course, at the IIS level or also using some HttpModule methods, I can change the request headers to tell the client when and how long the file should be cached.
Now I have a site where .aspx goes hand in hand with the corresponding .js. So, maybe I have some jQuery code in .js that accesses an element in .aspx. If I remove this element from .aspx, I would also adapt .js. If the user goes to my page, he will get a new .aspx, but he can still get the old .js, which will lead to funny effects.
My site uses many scripts and many images. For performance reasons, I configured in IIS that these files never expire.
Now the file changes from time to time, and I want users to receive update files.
In the beginning, I helped myself by renaming the files. So, I had ScriptV1.js and ScriptV2.js and so on. This is the worst case scenario since the repository history is broken and I need to adapt both the links and the file name.
Now I have improved and changed only the links using Script.js? v = 1 or script.js? v = 2. This forces the client to update files. It works fine, but still I need to adapt the links.
Now there is another improvement:
<script type='text/javascript' src='../scripts/<%# GetScriptLastModified("MyScript.js") %>'></script>
So, "GetScriptLastModified" will add a parameter? v = as follows:
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();
}
So the displayed .js-Link will look like this:
<script type='text/javascript' src='/scripts/GamesCharts.js?v=1377815076'></script>
, , , script , .
:
a) ?
) : - , ? 50 , .aspx GetScriptLastModified 50 .
:)