Question

I've purchased shared hosting with microhosting.in After putting together site for my start-up the natural next step was promote. So I checked for performance. Pagespeed tests pointed caching and uncompressed http as trouble. Now Windows hosting through Plesk means for any IIS feature requirement I've to explicitly convince the hosting provider, unless using Web.config will do. The technical team is abit weak to try things like http://blog.fi.net.au/?p=372 Using http for enabling public cache, as proxy caching might refrain meta-tags content sniffing, should be preferable. Is there any custom implementation that I may combine with Web.config that 'll apply these, as everywhere I find solutions using .htaccess?

Was it helpful?

Solution

Keep the optional content compressed within separate folder with its own web.config that compulsorily adds content encoding related attributes to header. For the compulsory content, rename the files to use asp.net runtime and place --> replacing ContentType with intended MIME type, nested within some tag as placing it outermost or uncommented as default irritates during server side xsl transformations. Now implement the following C# logic inside global.asax

 void Application_PreRequestHandlerExecute(object sender, EventArgs e)
 {
     HttpApplication app = sender as HttpApplication;
    string acceptEncoding = app.Request.Headers["Accept-Encoding"];
    Stream prevUncompressedStream = app.Response.Filter;

    if (acceptEncoding == null || acceptEncoding.Length == 0)
        return;

    acceptEncoding = acceptEncoding.ToLower();

    if (acceptEncoding.Contains("gzip"))
    {
        // gzip
        app.Response.Filter = new GZipStream(prevUncompressedStream,
            CompressionMode.Compress);
        app.Response.AppendHeader("Content-Encoding", "gzip");
    }       /*else if (acceptEncoding.Contains("deflate") || acceptEncoding == "*")
    {
        // defalte
        app.Response.Filter = new DeflateStream(prevUncompressedStream,
            CompressionMode.Compress);
        app.Response.AppendHeader("Content-Encoding", "deflate");
    }*/    // Only cache for X seconds.
Response.Cache.SetExpires(DateTime.Now.AddMonths(9));
Response.Cache.SetMaxAge(new TimeSpan(270, 0, 0,0,0));
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetValidUntilExpires(true);

// Sliding expiration means we reset the X seconds after each request.
// SetETag is required to work around one aspect of sliding expiration.
Response.Cache.SetSlidingExpiration(true);
Response.Cache.SetETagFromFileDependencies();

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top