Customize cache-busting in system.web.optimization
Asked Answered
V

3

6

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.

Vinegarroon answered 8/3, 2013 at 9:17 Comment(0)
B
4

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

Broncho answered 11/3, 2013 at 20:41 Comment(0)
F
9

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

Flourish answered 11/3, 2013 at 9:37 Comment(0)
B
4

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

Broncho answered 11/3, 2013 at 20:41 Comment(0)
S
0
<%: System.Web.Optimization.Styles.RenderFormat(NewOrders.SiteKeys.StyleVersion,"~/content/css") %>

In BundleConfig.cs C#:
 public class SiteKeys
    {
        public static string StyleVersion
        {
            get
            {
                return "<link href=\"{0}?v=" + ConfigurationManager.AppSettings["StyleVer"] + "\" rel=\"stylesheet\"/>";
              
            }
        }
    }
Sacculus answered 10/3 at 7:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.