Fix for uncompressed JS files on IIS

Jan 13, 2013

Rule #1 in website optimization is to enable GZip compression on the web server. This is very easy using web.config as explained here. However, some web servers have disabled automatic compression of JavaScript files, because they are served with the content type: application/x-javascript.

For these web servers we can use a web.config trick to change the content type of JavaScript files to text/javascript. This is a completely valid content type supported by all browsers.

Just paste the following XML snippet in to your web.config’s <system.webServer> section.

<staticContent>
  <remove fileExtension=".js"/>
  <mimeMap fileExtension=".js" mimeType="text/javascript" />
</staticContent>

Chances are that you don’t have this issue, since it seems to only apply to some hosters, but now you know how to get around it should you ever end up in the situation with uncompressed JavaScript files.

* $4.95/month ASP.NET Hosting with FREE SQL 2012 DB! – Click Here!

Comments (4) -

Internet marketing
Internet marketing India
1/22/2013 10:45:01 PM #

Thanks for sharing  .......

<a href="www.indiawebdesigncompany.in/">Website Design Company in Bangalore</a>

Internet marketing
Internet marketing India
1/22/2013 10:48:54 PM #

Thank you for publishing this information. This post is amazing.
www.bangalorewebdesigncompany.in/services.html

Anthom
Anthom Thailand
3/3/2013 6:58:09 AM #

I never ended up in the situation with uncompressed JavaScript files. But thanks for sharing this trick.
http://www.anthom-services.com

website marketing company
website marketing company Australia
3/20/2013 6:48:45 PM #

thanks for this men, I am a big follower of you regarding asp.net, and finally I got your blog and it solves my problem.

Comments are closed

About the author

Mads Kristensen

Mads Kristensen
Program Manager at the Microsoft Web Platform team and founder of BlogEngine.NET.

More...

Month List

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer’s view in any way.