Issues facing working with GZip - asp.net-mvc

I am facing a problem while trying to use GZip .
I have used the below entries in my config files i.e., applicationHost.config and web.config
<httpCompression>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" dynamicCompressionLevel="4" />
</httpCompression>
<urlCompression doDynamicCompression="true" doStaticCompression="true"/>
I have my application being deployed on IIS 7.5.
I have seen these suggestions over the net and I happen to hear that I would not need an exclusive stream code to be written. An entry to config file would suffice.
But still I get an error when my WCF service returns me a collection object with records over 1000. The object is a serializable object.
Please help me in this issue

Related

Gzip CSS Compression ASP.NET MVC

Using IIS10, ASP NET MVC 5
I have enabled dynamic and static compression in IIS and installed both features from Server Maanger. I added the below to my web.config:
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" />
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="application/json" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="application/atom+xml" enabled="true" />
<add mimeType="application/xaml+xml" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
The css files appear to be served in as gzip compressed and the Response header contains:
content-encoding:gzip
However, when rendered on the browser the css file is not being registering (ie non of the styles are being applied).
Is there a step I have missed?
Ensure that the Dynamic content Compression feature and Static Content Compression are installed.

JSON compression not working on Azure

I'm working on an MVC5 web app but can't make Azure perform dynamic compression on my JsonResults. The following code in my Web.config only works when I run the web app locally, but as soon as I deploy on Azure Web App the compression does not work:
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
<httpCompression>
<dynamicTypes>
<add mimeType="application/json" enabled="true" />
<add mimeType="application/json; charset=utf-8" enabled="true" />
</dynamicTypes>
<staticTypes>
<add mimeType="application/json" enabled="true" />
<add mimeType="application/json; charset=utf-8" enabled="true" />
</staticTypes>
</httpCompression>
I also tried the following, but with no luck:
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
<dynamicTypes>
<add mimeType="application/json" enabled="true" />
<add mimeType="application/json; charset=utf-8" enabled="true" />
</dynamicTypes>
<staticTypes>
<add mimeType="application/json" enabled="true" />
<add mimeType="application/json; charset=utf-8" enabled="true" />
</staticTypes>
</httpCompression>
This issue is really driving me crazy, I see no reason why this shouldn't work, considering that I found these solutions online from people who says that they implemented them successfully. Any idea?
I finally got what the problem was: some antiviruses (including mine, which is Bitdefender) interfere with the data compression mechanism, so from my computer I couldn't see the compression happening, while in reality it was working perfectly using the following Web.config markup:
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
<httpCompression>
<dynamicTypes>
<add mimeType="application/json" enabled="true" />
<add mimeType="application/json; charset=utf-8" enabled="true" />
</dynamicTypes>
<staticTypes>
<add mimeType="application/json" enabled="true" />
<add mimeType="application/json; charset=utf-8" enabled="true" />
</staticTypes>
</httpCompression>
For more info about similar issues, here is an interesting article about it: https://www.stevesouders.com/blog/2009/11/11/whos-not-getting-gzip/

cache static images by keeping Cache-Control set to no cache in asp.net mvc

I have images in my ~/Content/Images folder. And these images are used in Layout and other pages. When i request a page "Contact", it loads images referenced on that page and i can see requests in IIS log for each image load. This is ok for the first request. and for 2nd and further requests to contact page, i do not want these images to be requested from server again, want them to be load from cache.
I don’t want to change security settings in my web.config
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="no-cache, no-store" />
<add name="Pragma" value="no-cache" />
<add name="Expires" value="-1" />
</customHeaders>
</httpProtocol>
</system.webServer>
I am trying to add output cache setting for images as
<system.webServer>
<caching>
<profiles>
<add extension=".gif" policy="CacheUntilChange" kernelCachePolicy="DontCache" location="Client" />
<add extension=".jpg" policy="CacheUntilChange" kernelCachePolicy="DontCache" location="Client" />
<add extension=".jpeg" policy="CacheUntilChange" kernelCachePolicy="DontCache" location="Client" />
<add extension=".png" policy="CacheUntilChange" kernelCachePolicy="DontCache" location="Client" />
</profiles>
</caching>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
</staticContent>
</system.webServer>
But above setting still sending a requests for images each time I am refreshing the page.
do not want session values to be cached so I set cache-control to no-cache.
I want to stop these requests for static images until I change it.
What i am missing here?

Sitecore MVC - gzip compression error

I'm experiencing a problem when using Sitecore MVC 3 rendering with GZip content compression.
I followed the blog post of John West, how to enable MVC in Sitecore.
Until now it works perfectly, the pages are rendered. But if I run the page on IIS and enable content compression (gzip), the page doesn't load. I get a "Content Encoding Error" in Firefox. Other browser display various error messages.
Has somebody experienced similar issues? Do you have any idea what the problem may be? Where should I start checking? I have to use compression on the pages.
We are using Sitecore 6, Update 5: "Sitecore 6.6.0 rev. 130404"
Could this be a Sitecore bug?
EDIT 1: I am also running ASP.NET WebForms on the Sitecore instance and it works fine also with gzip compression.
EDIT 2: I have 'dynamicCompressionBeforeCache' enabled. My web.config related to gzip config:
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/javascript" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/javascript" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true" dynamicCompressionBeforeCache="true" />
Sitecore confirmed that they can reproduce the issue. When setting dynamicCompressionBeforeCache="true", the encoding does not work correctly for some reason.
One solution is to remove this setting. After applying dynamicCompressionBeforeCache="false" it works fine.
You should probably enable gzip in your web.config
<system.webServer>
<httpCompression directory="%SystemDrive%\inetpub\
temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll"/>
<dynamicTypes>
<add mimeType="text/*" enabled="true"/>
<add mimeType="message/*" enabled="true"/>
<add mimeType="application/javascript" enabled="true"/>
<add mimeType="*/*" enabled="false"/>
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true"/>
<add mimeType="message/*" enabled="true"/>
<add mimeType="application/javascript" enabled="true"/>
<add mimeType="*/*" enabled="false"/>
</staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true"/>
</system.webServer>
There are a few more tricks here
Setting the gzip compression in asp.net

Mvc 4 script bundles and GZip

I've add all scripts from my site into very big bundle (about 700kb). And now I want IIS to gzip it, but i can't.
I've tried everything I've found here and over the web, but nothing helps. Static *.js files age gzipped, but complete bundle not.
Is there any solution ?
Check the dynamic compression in IIS. It have to be enabled for both IIS and your website. You also must have a valid config in the applicationHost.config too.
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="application/json" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="application/atom+xml" enabled="true" />
<add mimeType="application/xaml+xml" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
</httpCompression>
Important Note : the content type of Bundling response is text/javascript, so check your config for this type.

Resources