Recent technical conversation with few of my friends ends up with Issue of site speed , no matter what we do the site loads too slow – and seriously speaking this is something came across me too. I spent around 2 weeks to find out the better solution to optimize speed of the asp.net / mvc3 websites – which supports IIS7
There are few things I found is
1. cache… cache….. cache everything you can !
2. compress the static/dynamic content.
3. make sure you take off all the content you don’t need OR load them later if you are not using them in page load !
How to cache the page content ?
There are plenty of ways out there to cache the page content , for site of asp.net / mvc – in general any website that supports web.config (in other words – generally website hosted in IIS server ) can be optimized using following lines of code to web.config
<clientCache cacheControlMaxAge=”365.00:00:00″ cacheControlMode=”UseMaxAge” />
where cacheControlMaxAge attribute is <days>.<hours>:<min>:<sec>
Compress the Content , But how ?
Here comes few prerequisites – that your IIS 7 must have dynamic content compression module installed ! most of the hosting supports dynamic compressions
To enable dynamic compression in the asp.net / mvc website add following to web.config
<urlCompression doDynamicCompression=”true” doStaticCompression=”true” dynamicCompressionBeforeCache=”true”/>
On demand Script loading
Generally we do load all the scripts in <head></head> – which ends up with loading all the scripts before loading your page content !
Its advisable to load ONLY necessary scripts which are required during page load animations or any content bindings – rest can be added to load before </body>, that will make your site speed noticeably faster.
Again , these are the steps I performed to optimize my website , If you come across something good ; let everyone knows to speed up their site – please leave ideas in comments.
Happy coding !