<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How to create a browser cache save URL to a javascript or css file in SharePoint</title><link>http://blogs.technet.com/stefan_gossner/archive/2009/04/08/how-to-create-a-browser-cache-save-url-to-a-javascript-or-css-file-in-sharepoint.aspx</link><description>Often it is necessary to ensure that updates to files on the server get populated to the client asap. Especially when it comes to dependencies to custom javascript of CSS files and server controls. SharePoint itself does this by adding a query string</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Actually, there's a lot more elegant solution to serving files from "_layouts"</title><link>http://blogs.technet.com/stefan_gossner/archive/2009/04/08/how-to-create-a-browser-cache-save-url-to-a-javascript-or-css-file-in-sharepoint.aspx#3224174</link><pubDate>Wed, 08 Apr 2009 22:28:27 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3224174</guid><dc:creator>Anders Borum</dc:creator><description>&lt;p&gt;We had an issue for a major client related to HTTP content expiration of resources served from &amp;quot;_layouts&amp;quot;, and I'd like to share my findings (so please correct me if I'm wrong). We decided not to use the API you're referring to, because&lt;/p&gt;
&lt;p&gt;a) it works against the IIS infrastructure and common sense (there's no reason to hash static binaries when the IIS infrastructure provides this for free and serves the right HTTP status codes).&lt;/p&gt;
&lt;p&gt;b) it leaves a lot of stale files in the users' browser (change the original file on the server by mens of deployment, and the user will never make use of the file again).&lt;/p&gt;
&lt;p&gt;When SharePoint creates the &amp;quot;_layouts&amp;quot; virtual directory in IIS, it also configures HTTP content expiration with a value of 1 year (expressed in seconds). Effectively, this instructs the browser to hang on to the resource for a full year and never ever ask for changes to the original file.&lt;/p&gt;
&lt;p&gt;Unless the user actually initiates a forced reload (F5, CTRL+F5 or whatever), there's no way users will receive your changes to any resources requested from the &amp;quot;_layouts&amp;quot; virtual directory. By default (and regardless of the expiration settings in most browsers), when a new instance of the browser is started, a full requests for all associated resources is initiated; the HTTP responses from the server might be mixed HTTP 200s (OK) or HTTP 302s (Not Modified).&lt;/p&gt;
&lt;p&gt;In general, using querystring params to flag a resource as changed is something you should really consider not doing; it's much better to use HTTP headers. Also, if you opt for the HTTP content expiration route, make sure you use a more sensible value than a full year; odds are you'll make changes to your &amp;quot;static&amp;quot; files in the mean time and want the browsers to reflect that.&lt;/p&gt;
&lt;p&gt;Anders Borum&lt;/p&gt;
&lt;p&gt;Software Architect, ProActive A/S&lt;/p&gt;
&lt;p&gt;Denmark&lt;/p&gt;</description></item><item><title>re: How to create a browser cache save URL to a javascript or css file in SharePoint</title><link>http://blogs.technet.com/stefan_gossner/archive/2009/04/08/how-to-create-a-browser-cache-save-url-to-a-javascript-or-css-file-in-sharepoint.aspx#3224192</link><pubDate>Wed, 08 Apr 2009 23:21:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3224192</guid><dc:creator>Stefan_Gossner</dc:creator><description>&lt;p&gt;Hi Anders, &lt;/p&gt;
&lt;p&gt;an interesting discussion point!&lt;/p&gt;
&lt;p&gt;Lets jump on the browser behavior first: most browsers indeed behave or first request after a restart as if the content in the cache has expired. But this is not controlable by the server. &lt;/p&gt;
&lt;p&gt;Regarding the one year for content expiration and the query string values:&lt;/p&gt;
&lt;p&gt;The goal is to minimize network requests and especially the amount of data downloaded to the client.&lt;/p&gt;
&lt;p&gt;On the other hand it needs to be ensured that when you install a hotfix that replaces a control and with the control a javascript file that has specific code for this control are in sync.&lt;/p&gt;
&lt;p&gt;The server cannot control when the browser refreshes his cache.&lt;/p&gt;
&lt;p&gt;Hotfix install cycles also cannot be predicted by the product team in advance.&lt;/p&gt;
&lt;p&gt;So what could you do here to ensure that the control executed on the server and the javascript file loaded into the browser is always in sync?&lt;/p&gt;
&lt;p&gt;1) disable caching - not a good option with the large js files sent by sharepoint&lt;/p&gt;
&lt;p&gt;2) configure the expireation to the time when the content will change - that is more or less impossible as it is usually not predictable when content will change in the future.&lt;/p&gt;
&lt;p&gt;3) configure a small expiration value - e.g. 5 minutes - that causes lots of network traffic to check if the file has been changed or not. Overhead that should be avoided if possible. In case that no hotfix installed then it could take 1 year or longer for the file to get changed: when the next service pack is released and installed. But even then - if only a small number of files is replaced - there is a nearly 5 minute timeframe where errors can occur on the client side because the javascript file and the rendered content from the updated control is no longer in sync.&lt;/p&gt;
&lt;p&gt;4) use a query string - that has the benefit that you can ensure that the javascript file and the control are always in sync: changing the static file will cause a different query string to be generated. The only caveat I can see with this approach is that the browser cache gets filled with a different copy for each update.&lt;/p&gt;
&lt;p&gt;But how often will you change the files? I think the overhead in used disk space on the browser for regular update cycles is pretty low.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Stefan&lt;/p&gt;
</description></item><item><title>re: How to create a browser cache save URL to a javascript or css file in SharePoint</title><link>http://blogs.technet.com/stefan_gossner/archive/2009/04/08/how-to-create-a-browser-cache-save-url-to-a-javascript-or-css-file-in-sharepoint.aspx#3224201</link><pubDate>Wed, 08 Apr 2009 23:38:33 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3224201</guid><dc:creator>Gaël Duhamel</dc:creator><description>&lt;p&gt;What about the HttpCombine ? Check this out: &lt;a rel="nofollow" target="_new" href="http://www.codeproject.com/KB/aspnet/HttpCombine.aspx"&gt;http://www.codeproject.com/KB/aspnet/HttpCombine.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Ga&amp;#235;l&lt;/p&gt;</description></item><item><title>re: How to create a browser cache save URL to a javascript or css file in SharePoint</title><link>http://blogs.technet.com/stefan_gossner/archive/2009/04/08/how-to-create-a-browser-cache-save-url-to-a-javascript-or-css-file-in-sharepoint.aspx#3224208</link><pubDate>Wed, 08 Apr 2009 23:56:11 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3224208</guid><dc:creator>Stefan_Gossner</dc:creator><description>&lt;p&gt;Hi Gael,&lt;/p&gt;
&lt;p&gt;also an interesting approach! It is good if your performance killer is network latency. But not if it is network speed in general.&lt;/p&gt;
&lt;p&gt;The caveat with this approach: if the sum of all your JS files is 500 KB and you change a 10 KB js file then again all 500 KB have to be downloaded.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Stefan&lt;/p&gt;
</description></item><item><title>I agree with the MOSS way</title><link>http://blogs.technet.com/stefan_gossner/archive/2009/04/08/how-to-create-a-browser-cache-save-url-to-a-javascript-or-css-file-in-sharepoint.aspx#3233352</link><pubDate>Thu, 30 Apr 2009 14:46:18 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3233352</guid><dc:creator>Michhes</dc:creator><description>&lt;p&gt;To summarise the above, there's not way for the server to tell the browser to use an updated file if the file a) uses the same name and b) is cached without changing the file name or using a technique like this. Changing the file name (eg. versioning it or datestamping it) could be disruptive and the querystring approach sounds like the next best option. Presumably the browser will delete cached files as its maximum cache threshold is reached so caching multiple files on the client shouldn't be a major consideration.&lt;/p&gt;</description></item></channel></rss>