Should you be gzipping html pages? If so how to do it in .net?
I am looking at my performance in yslow and even though I gzipped my css and js scripts it says I should gzip my html page.
Compression reduces response times by reducing the size of the HTTP response. Gzip is the most popular and effective compression method currently available and generally reduces the response size by about 70%. Approximately 90% of today's Internet traffic travels through browsers that claim 开发者_C百科to support gzip.
I am wondering should I do this? And if so how do you do that when using asp.net mvc with C#?
Yes, you should be doing this, it'll dramatically reduce your payload delivered to the client (faster page load, yay!). This is done in IIS (if you have the option, it's not the only option, e.g. blowery, etc).
- IIS7
- If you're on IIS7 (hopefully the case), you can find instructions here.
- If you may not have direct access, here's the
web.config
<httpCompression>
section docs to do the setup directly. IIS7 can be configured a great deal (depending on what your host allows) from theweb.config
alone.
- IIS6
- Similarly, for IIS6 (less built-in options for dynamic content) the instructions are here.
Disclaimer: There is some cost to doing this in terms of CPU to actually do the compression. However, it's always been worth it in my experience. If you have an extremely high traffic site, you may need to weigh the costs though (though if you pay for bandwidth, I'd bet it's still a clear win).
Static resources are gzipped by default. You only need access to IIS to configure compression of dynamic resources.
This is probably a premature optimization.
"Premature Optimization is the root of all evil." -Knuth
Writing new features and making your site better is probably a more efficient use of your time.
精彩评论