Writing HTML and CSS which complies with the W3C standards means that it will be interpreted consistently by modern browsers.
Invalid HTML can slow down page load as the browser has to do unnecessary processing.
Invalid CSS can slow down the rendering time of a page.
Run your HTML through the W3C HTML Validator and CSS through the W3C CSS validator.
Alternatively, you can incorporate HTML validation into your workflow with the Grunt HTML validation package and Stylelint
2.Not Leveraging Browser Caching
Caching reduces the load time of web pages for repeat visitors by storing files on a user’s browser. Stored files do not need to be fetched or loaded again for a specified period.
When users first visit a site, resources are fetched over the network and may require multiple trips between the client and server. Caching stores commonly used files, making subsequent site visits faster. To enable browser caching, add the Cache-Control and ETag (entity tag) headers to HTTP response headers. Cache-Control defines how, and the period of time, a response can be cached by the browser and other caches. ETag provides a validation token, used to communicate with the server, to check if a resource needs to be updated. Learn more about leveraging browser caching.
3. Non-Optimized Images
Images on a page can be optimized to reduce their file size without impacting the quality.
A large number of websites use images, and images usually account for most of the downloaded data on a page. Optimizing images is one of the easiest ways to increase page performance.
Ways to optimize images:
4. Uncompressed CSS and JavaScript
The size of a CSS or JavaScript file can be reduced through minification.
Minification is the process of removing all unnecessary characters from code while maintaining its functionality.
Minifying CSS and JavaScript:
Minification also reduces network latency (the time it takes for data packets to get from one point to another), leading to faster browser load times.
To minify stylesheets, try CSSNano and csso. CSSNano can be integrated into your workflow as a plugin for postcss.
To minify JavaScript, try UglifyJS2. You can also utilize UglifyJS in your workflow through the Grunt plugin, or Gulp plugins like gulp-uglify or gulp-sourcemaps.
评论