ASP.NET MVC / IIS - Optimizing Web Application Performance
Optimizing your web sites in ASP.NET MVC for performance includes cache busting, enabling caching for static resources, enabling gzip compression.
To enable caching on static resources, you will need to add the following XML in your web configuration file in the system .webserver element. The control max age parameter determines the length of time to cache the static resources.
In an effort to compress dynamically generated content (ASP, PHP, ASP.NET) and static files (PDF, JPEG, etc.), you can enable the following settings within your application web configuration. As you use <urlCompression> to define what is compressed, you can use <httpCompression> to define how it is compressed.
Utilizing Cache Busting can be done to ensure users do not need to clear their browser cache (temporary internet files, etc.) to see changes. Enabling this within the BundleConfig, script and style bundles, when bundles are rendered, will include version numbers.
You will want to ensure the following module is added within the web configuration.
Within your BundleConfig.cs file, you will need to utilize:
1 2 3 4 5 6 7 8 9 | < system.webserver > ... < staticcontent > ... <!--— Cache Static Resources (CSS, IMG, JS) for 365 Days —--> < clientcache cachecontrolmode="UseMaxAge” cacheControlMaxAge = " 365.00:00:00" =""> </ clientcache ></ staticcontent > </ system.webserver > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | < system.webserver > <!--— Utilize GZIP HTTP Compression —--> < 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" > </ add ></ add ></ add ></ add ></ add ></ 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" > </ add ></ add ></ add ></ add ></ add ></ add ></ statictypes > </ scheme ></ httpcompression > … <!--— Utilize GZIP Url Compression —--> < urlcompression dostaticcompression = "true" dodynamiccompression = "true" > </ urlcompression ></ system.webserver > |
1 2 3 4 | < modules > < remove name = "BundleModule" > < add name = "BundleModule" type = "System.Web.Optimization.BundleModule" > </ add ></ remove ></ modules > |
1 | BundleTable.EnableOptimizations = true ; |
Comments