3 Ways to Reduce JS Page Load Times
Everyone dislikes waiting for pages to load, but it can be hard figuring out ways to improve load times for users.
Caching
Caching through a service like nginx is probably the best way to drastic reduce load times. What it does, is allow a static version of the site to be displayed, that does not need to be retrieved from a database. You may wonder, “how do I change show personalized information”? Easy, just ensure those pages pull the latest changes in realtime from your database. When deployed, it should be a smooth transition between static and non-static pages.
Lodash
Lodash is underscore’s more performant cousin. With its driving goal to be more performant than underscore, you can ensure its functions will help reduce load times. One of the most common mistakes a junior developer makes is requiring for loops or even JS’s native forEach. While the former is worse, Lodash _.forEach is the most performant option.
Minified CSS
The final easy fix, is just minify your CSS. At the basic level you can write your CSS normally then plug it into a tool like cssminifier.com. As you get more advanced though, you will most likely use a tool like Grunt, Gulp, or webpack to do this for you. There’s three suggestions are great way to ensure your user’s spend more time on your site and less time waiting to get there.