Sitefinity websites can contain a large amount of JavaScript files, possibly up to a megabyte. Thus enabling HTTP compression can significantly increase the performance of your website.
YSlow stats of a Sitefinity page with a lot of JavaScript.
To enable HTTP compression first add this under system.webServer in the web.config
<
urlCompression
doDynamicCompression
=
"true"
dynamicCompressionBeforeCache
=
"true"
/>
<
httpCompression
cacheControlHeader
=
"max-age=86400"
noCompressionForHttp10
=
"false"
noCompressionForProxies
=
"false"
sendCacheHeaders
=
"true"
minFileSizeForComp
=
"1"
/>
Then this in the ServiceDefinition.csdef file under the Webrole
<
Startup
>
<
Task
commandLine
=
"EnableCompression.cmd"
executionContext
=
"elevated"
taskType
=
"simple"
></
Task
>
</
Startup
>
Then create the EnableCompression.cmd file in the bin directory of your project - make sure to include it in your project and set the build action to Content. Enter into the file this code
REM Remove old settings - keeps local deploys working (since you get errors otherwise)
%windir%\system32\inetsrv\appcmd reset config -section:urlCompression
%windir%\system32\inetsrv\appcmd reset config -section:system.webServer/httpCompression
REM urlCompression
%windir%\system32\inetsrv\appcmd set config -section:urlCompression /doDynamicCompression:True /commit:apphost
REM IIS Defaults
%windir%\system32\inetsrv\appcmd set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='text/*',enabled='True']" /commit:apphost
%windir%\system32\inetsrv\appcmd set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='message/*',enabled='True']" /commit:apphost
%windir%\system32\inetsrv\appcmd set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/x-javascript',enabled='True']" /commit:apphost
%windir%\system32\inetsrv\appcmd set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='*/*',enabled='False']" /commit:apphost
%windir%\system32\inetsrv\appcmd set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='text/*',enabled='True']" /commit:apphost
%windir%\system32\inetsrv\appcmd set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='message/*',enabled='True']" /commit:apphost
%windir%\system32\inetsrv\appcmd set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='application/javascript',enabled='True']" /commit:apphost
%windir%\system32\inetsrv\appcmd set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='*/*',enabled='False']" /commit:apphost
REM Set dynamic compression level to appropriate level. Note gzip will already be present because of reset above, but compression level will be zero after reset.
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"[name='deflate',doStaticCompression='True',doDynamicCompression='True',dynamicCompressionLevel='7',dll='%%Windir%%\system32\inetsrv\gzip.dll']" /commit:apphost
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression -[name='gzip'].dynamicCompressionLevel:7 /commit:apphost
This will ensure that JavaScript and text content such as css files will also be compressed using gzipped and not just the page html.
With the compression enabled you should see a big decrease in the filesize of the JavaScript being sent to the browser on your page. For example here is the example of a page without compression:
And now using the compression:
We have reduced the size of just our JavaScript by 65%, shaving off 765.9kb from our page just from the JavaScript alone! Combined with the compression of the page itself and css files the total amount of content the page loads has been reduced 53%, or almost 1 and a half megabytes.
In summary, enabling HTTP compression gives your site a significant boost to performance all for the cost of editing some config files.