Optimize your JavaScript, CSS and HTML code

How to optimize your JavaScript, CSS and HTML code. Please add to and improve upon the techniques that already listed.

Overview

Code optimization is now an important task with the Web Experience Toolkit taking a mobile-first approach in version 4.0. Where sluggish code may have minimal impact on desktop browser performance, it can result in very noticeable delays on mobile devices. That is why a main focus of WET v4.x is performance optimization.

The WET v4.x framework is already heavily optimized using code minification, consolidation, CSS spriting and Base64 encoding. All of these result in significant performance increases but can still be bogged down by bloated and sluggish code. This page provides many tips for ensuring your code is as efficient as possible.

JavaScript code optimization

Testing your optimizations

To test your optimization changes, wrap a block of code with the following two lines of code.

var test = ( new Date() ).getTime();
// Code to test
console.log( ( new Date() ).getTime() - test );

Another option is to use a site like jsPerf to benchmark different JavaScript code snippets.

jsPerf Test Cases

Additional techniques

CSS code optimization

Additional techniques

HTML code optimization

Web server optimization

Date modified: