Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize cache-busting in system.web.optimization

When rendering the styles from bundles when optimization is on you get this:

<link href="/Content/themes/base/css?v=UM624qf1uFt8dYtiIV9PCmYhsyeewBIwY4Ob0i8OdW81" rel="stylesheet" type="text/css" />

Unfortunately the Android browser do not seem to load urls with query strings on them. Is there some way you can customize this string in System.Web.Optimization?


Edit:

My question is answered and I tried to detect android on user agent string and replace with a querystring less link to the stylesheet. Apparently the problem I had wasn't because of the querystring, it was minified version of the webfont css that was causing it not to load the stylesheet completely in the Android stock browser.

Android stock browser fails to load css content string with escaped backslash which was a workaround for the ASP.NET minifier that erronously minifies the same css content string. I ended up putting the icon font css styles on it's own "minified by hand" stylesheet.

like image 420
Spoike Avatar asked Mar 08 '13 09:03

Spoike


2 Answers

You can disable caching by using

@{string path = BundleTable.Bundles.ResolveBundleUrl("~/bundle/cssCommon", false);}
//may apply manual path transformation to remove ?v= anyway
<link href=@path rel="stylesheet" type="text/css" />

or short form

<link href="@BundleTable.Bundles.ResolveBundleUrl("~/bundle/cssCustom", false)"

But you will have caching-related problems instead of android WebView problems. Another possible approach is using Microsoft Ajax Minifier

like image 135
Danila Polevshchikov Avatar answered Sep 23 '22 18:09

Danila Polevshchikov


We don't currently support customizing how the version string appears in the url unfortunately.

This is a link to the issue on our codeplex site: Url version issue

In the meantime, if you are willing to live with manually rev'ing the bundle path every time you change the bundle, you could just avoid using the helpers and just having explicit links to your bundles which you update each time your bundle changes:

<link href="/Content/themes/base/css" rel="stylesheet">

Or you could disable caching on the client via bundle.Cacheability = HttpCacheability.NoCache

like image 34
Hao Kung Avatar answered Sep 21 '22 18:09

Hao Kung