Combine And Minify JS and CSS To Optimize Website Speed

Combining And Minifying JS and CSS Can Optimize Your Website Speed

On a website, sometimes the largest files are the javascript (JS) and the cascading style sheets (CSS). There also tends to be many of them due to the different applications and components that make your website functional. Each of them count as an additional HTTP request needed by the browser. For example, if you have 10 JS files and 10 CSS files that are needed, then there will be a total of 20 individual requests just for JS and CSS. 

Each of those requests take up valuable time and bandwidth. One way to reduce this issue to combine your JS files into 1 file and your CSS files into 1 file as well. That way your 20 requests drop down to just 2 requests. In addition, this can be plenty of white space in between the text lines in each of these files because human coders need that to see where specific sections begin and end. Minifying these files can help reduce the overall size of them by deleting the while space out.

Be Careful On Combining JS and CSS files

Although this can be an effective method on saving HTTP requests, this could break your website. Some of the applications need to have their JS and or CSS in a separate file due to how the page is loaded. For example, lets say you have a A/B test application that is going to generate a specific page based upon the user’s test group - A or B. This application needs to have it’s javascript loaded first and not combined with other JS because it needs to assess the group that the visitor lands in before the page is generated, then generate the A or B version of the page. If a page like this is generated with improper combining of JS, the page will look strange, incomplete, or unable to render at all.

You Have To Be Careful With Minifying JS And CSS Files

In some cases, minifying the file can actually harm the website as well. In some cases, if you use a poorly written minify code, the CSS or JS code will become corrupted and cause the page to show up incorrectly or not render at all. In some cases, it will break functionality of some pieces of the website - but not the entire thing. So it’s always a good idea to check all aspects of your website before setting this live.

If you’ve done it correctly, you should see a performance increase.

Proper use of Combine and Minify JS and CSS will help increase your website speed and result in better user experience. In addition, increased site speed will also help you with SEO as the search engines like faster performing websites in favor of the poorly performing ones. 

There are other ways to improve your website loading speed!

Check out our article on the other methods to improve the speed of your website.

Need help optimizing your website? Contact us today to help with your website speed and SEO

Sign Up For Our Newsletter