tag:blogger.com,1999:blog-4126985520350746834.post4253796625993791111..comments2024-03-28T07:00:21.554+00:00Comments on Chris O'Brien: Avoiding bugs from cached JavaScript and CSS files in SharePointChris O'Brienhttp://www.blogger.com/profile/10022906552670607366noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-4126985520350746834.post-348920634317760212014-11-18T17:05:03.206+00:002014-11-18T17:05:03.206+00:00Old post, but should be added here as this is very...Old post, but should be added here as this is very high in search ranking.<br /><br />Make use of SPUtility.MakeBrowserCacheSafeLayoutsUrl in SharePoint 2013: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.sputility.makebrowsercachesafelayoutsurl.aspxmoontearhttps://www.blogger.com/profile/12073084723428945701noreply@blogger.comtag:blogger.com,1999:blog-4126985520350746834.post-54719463991880923682012-04-24T14:14:07.886+01:002012-04-24T14:14:07.886+01:00Apparently ?rev= is only appended by CssRessources...Apparently ?rev= is only appended by CssRessources if you place your CSS file under 1033/styles or similar language specific folder, and not in _Layouts/stylesAnders Raskhttp://andersrask.sharepointspace.comnoreply@blogger.comtag:blogger.com,1999:blog-4126985520350746834.post-81621453158414901802011-12-04T16:08:54.757+00:002011-12-04T16:08:54.757+00:00@Mel,
Nice. Any idea if this works off the file c...@Mel,<br /><br />Nice. Any idea if this works off the file contents, so the querystring only changes when it absolutely needs to (so users get the full caching benefit)?<br /><br />Thanks,<br /><br />Chris.Chris O'Brienhttps://www.blogger.com/profile/10022906552670607366noreply@blogger.comtag:blogger.com,1999:blog-4126985520350746834.post-83751118792055942252011-12-04T16:06:33.961+00:002011-12-04T16:06:33.961+00:00@Lee,
I see your thinking but unfortunately not (...@Lee,<br /><br />I see your thinking but unfortunately not (I tested this too, see my table above). This makes sense in fact, because what matters are the headers when the file was <strong>initially</strong> served (however long ago this was).<br /><br />Cheers,<br /><br />Chris.Chris O'Brienhttps://www.blogger.com/profile/10022906552670607366noreply@blogger.comtag:blogger.com,1999:blog-4126985520350746834.post-52766927054501439532011-12-04T16:01:59.192+00:002011-12-04T16:01:59.192+00:00@Mahmoud,
Excellent detective work! I re-tested a...@Mahmoud,<br /><br />Excellent detective work! I re-tested and saw the same behaviour. I think this could change the issue significantly for some people, and soon I'll update the article accordingly. <br /><br /><strong>However,</strong> interestingly this wouldn't help our project because we don't exclusively use ScriptLink for ALL our JavaScript references (we used ClientScriptManager + direct <script> tags via a DelegateControl also). This is because we had some dependencies in our JS files, and couldn't express these with purely the ScriptLink control. Maybe we missed something, but if not I think the mixed reference model could be common - meaning the thrust of my argument would still stand.<br /><br />Thanks, great contribution!<br /><br />Chris.Chris O'Brienhttps://www.blogger.com/profile/10022906552670607366noreply@blogger.comtag:blogger.com,1999:blog-4126985520350746834.post-88948923574494826172011-12-04T15:56:55.265+00:002011-12-04T15:56:55.265+00:00@Mark,
Agreed - SharePoint's own caching head...@Mark,<br /><br />Agreed - SharePoint's own caching headers for the 'layouts' directory are added in IIS (not by any internal SharePoint code), this is all configured when SharePoint creates a website in IIS.<br /><br />Not sure how effective the idea of changing directives in the run-up to a deployment would be though. Consider that users who visited your site 6 months ago (and never since) would still receive stale files even if you used this technique, since the headers they received 6 months ago said "cache for 1 year". Maybe there are other circumstances where it is useful though.<br /><br />Thanks,<br /><br />Chris.Chris O'Brienhttps://www.blogger.com/profile/10022906552670607366noreply@blogger.comtag:blogger.com,1999:blog-4126985520350746834.post-5633091292555820692011-12-03T10:41:05.534+00:002011-12-03T10:41:05.534+00:00Hi Chris,
Great post, I recently addressed this ...Hi Chris, <br /><br />Great post, I recently addressed this same issue on a project I'm currently working on - admittedly not SharePoint but obviously the same principals apply. I ended up integrating this into the build process by using the FileUpdate task in 'MSBuild Community Tasks' to update a querystring version on the static resources in each master page on deployment. The FileUpdate task is pretty cool as it takes a regex to match the path:<br /><br />http://geekswithblogs.net/mnf/archive/2009/07/03/msbuild-task-to-replace-content-in-text-files.aspx<br /><br />CheersMel Lotahttp://www.auronmedia.co.uknoreply@blogger.comtag:blogger.com,1999:blog-4126985520350746834.post-3276076370849130772011-12-01T12:23:29.231+00:002011-12-01T12:23:29.231+00:00Hi Chris,
After I read your post and read this sec...Hi Chris,<br />After I read your post and read this section “ScriptLink DID add querystring ?rev=q%2Fb304kubfwrNJVD%2BdYdxg%3D%3D, but not clear when this gets updated – NOT when file changes”. I reflect the ScriptLink and CssLink controls to see how they render the url and I found that they use this method “SPUtility.MakeBrowserCacheSafeLayoutsUrl”which add the “rev” based on the file content so when you update the file the rev is changed. So just to make this work you need to add your files under the _layout folder do update reset IIS and your url will be updated. I hope that this fix your problem.Mahmoud Hamedhttps://www.blogger.com/profile/08928561543630720255noreply@blogger.comtag:blogger.com,1999:blog-4126985520350746834.post-71135557525633649892011-11-30T16:32:59.699+00:002011-11-30T16:32:59.699+00:00It's also worth mentioning that IIS may have c...It's also worth mentioning that IIS may have caching headers over and above what you are doing in code.<br /><br />A good inspection with Fiddler is essential and working out which stage of the response pipeline is setting headers. To increase scalability I have seen sites where expiration was set in the region of days which severely affected the ability to upgrade the application.<br /><br />Changing IIS caching directives in the run up to an upgrade can help alleviate this sometimes.Mark Wilsonhttps://www.blogger.com/profile/06718232619735410417noreply@blogger.com