Thursday, 3 December 2015

ASP.NET Tips #55 - Send as little as possible to the web browser

Web page load time is often limited by network latency, which can range in the hundreds of milliseconds, especially for mobile devices. The more files are transferred and the larger those files, the more round trips will be needed, so the greater the impact the latency will have. As a developer, there's rarely much you can do to reduce the latency, but you can cut down the number of times the round trip cost is incurred.

HTTP compression should always be turned on, and makes a particularly big impact for easily compressible content like html. Minificafion and bundling of JavaScript & CSS files can be automatically handled by ASP.NET from v4.5 onwards. Just make sure you set BundleTable.EnableOptimizations = true;

If you're including libraries like jQuery, serve it up from Google or Microsoft's free CDNs. Google's datacenters are probably better than yours, and it’s very likely a user will already have a cached copy of the same library from having visited other websites using the same CDN, entirely eliminating their browser’s need to re-download it. It also reduces your own server's load and bandwidth.

Clear out the cruft! A new ASP.NET project includes many libraries, not all of which are necessarily used, and if something's being unnecessarily sent to the client, it's incurring performance cost for no good reason. It can also be astonishing how many libraries get added to a project over time, but not removed when they stop being required. An occasional spring clean helps keep this in check.

No comments :

Post a comment