Nomal Afzal Nomal Afzal - 2 months ago 32
ASP.NET (C#) Question

Remove query strings from static resources

My website is running on ASP.NET platform and recently i test my website on pingdom and i found the below error.


Resources with a "?" in the URL are not cached by some proxy caching
servers. Remove the query string and encode the parameters into the
URL for the following resources:
https://projectsdeal.co.uk/ScriptResource.axd?d ...
63Nawdr4rAt1lvT7c_zyBEkV9INg0&t=ffffffffe3663df5
https://projectsdeal.co.uk/ScriptResource.axd?d ...
JGTlZFM0WRegQM9wdaZV3fQWMKwg2&t=ffffffffe3663df5


Here is the screenshot check it

Answer

Simple leave it as it is (its not an error !) - you can not remove this query string from resource because this is the id on how to load that resource from asp.net

The message that you get is actually talk for a proxy caching servers - what is a proxy caching server ? a middle computer that cache pages of your site, not the actually client computer - that can hold in cache that page and not bring slower your site in general.

So your client can hold that resource on cache if you set them correctly, and from what I see asp.net take care correctly and you resource are cached just fine - see this screen shot.

enter image description here

Now if you wish to add even more aggressive cache you can use the global.asax and do something like

protected void Application_BeginRequest(Object sender, EventArgs e)
{
    string cTheFile = HttpContext.Current.Request.Path;

    if (cTheFile.EndsWith("WebResource.axd", StringComparison.InvariantCultureIgnoreCase))
    {
        JustSetSomeCache(app);
    }
}

private static void JustSetSomeCache(HttpApplication app)
{
    app.Response.Cache.AppendCacheExtension("post-check=900, pre-check=3600");
    app.Response.Cache.SetExpires(DateTime.UtcNow.AddHours(32));
    app.Response.Cache.SetMaxAge(new TimeSpan(32, 0, 0));
    app.Response.Cache.SetCacheability(HttpCacheability.Public);
    app.Response.AppendHeader("Vary", "Accept-Encoding");
}

What is the different ? The second cache is not check the server at all for file change as the asp.net do, you can gain one webserver call.

Comments