Ask Yoast Why and how to minify your JS and CSS

If you check your site speed with Google PageSpeed Insights you might get the advice to minify your Javascript (JS) and Cascading Style Sheets (CSS) files. Your JS files contain the code for the interactive elements of your website. And in your CSS files, you specify the design of your pages. Minifying those files will decrease your page load time, thereby providing a better user experience.

We received the following question about minification of JS and CSS files in our Ask Yoast inbox:

“Why and how should I minify my JS and CSS files?”

Check out the video or read the answer below!

Minify your JS and CSS files

Improve your technical SEO skills!

  • Which technical SEO errors hurt your site?
  • Solve them and climb the rankings!
  • Improve your site speed on the go
  • On-demand SEO training by Yoast
More info

“JavaScript (JS) is the stuff that makes your web page interactive and CSS is the stuff that makes your web page look good. Basically, these two things are code that you send to the browser, and that the browser needs to render.

 

A browser, like any other computer program, doesn’t care what the language that it receives, looks like. It doesn’t need the spacing and the comments and all other stuff, that your developer needs to make sense of it all. He needs the structure to get through the code, however, the browser has no benefit from that.

Stripping all of that down actually makes the file that you send to the user a lot smaller. Because when you minify it, you remove all the extra spaces, all the line breaks, and all the comments. Stripping all that can save up to 30-40%, or even 50% of file size in some cases. There really is no benefit of sending that stuff to the end-users, so minifying saves time and money for everyone. 

That’s why you should do it. Good luck!”

If you’re on WordPress, there’s a vast amount of plugins that can help you minify your HTML, CSS and JS files. We generally recommend WPRocket for this and some further improvements to speed up your site.

Ask Yoast

In the series Ask Yoast we do our best to answer your SEO question! Need some help with your site’s SEO? Send your question to ask@yoast.com. You might get a personal answer on video!

Note: you may want to check our blog and knowledge base first, the answer to your question could already be out there! For urgent questions, for example about the Yoast SEO plugin not working properly, please contact us through our support page.

Read more: DIY: optimize your browser cache »

Ask Yoast series


6 Responses to Ask Yoast: Why and how to minify your JS and CSS

  1. John
    John  • 2 years ago

    Great information here, I agree it can be used. Yoast has helped with guiding our sites in the right direction.

  2. Patrick
    Patrick  • 2 years ago

    Thank you for your awesome plugin and your awesome articles. Greetings from Germany

  3. Willis
    Willis  • 2 years ago

    This has some great info here related to this article. I was thinking if you had any more info ?

  4. James
    James  • 2 years ago

    You had some great information here that I highly agree can be used. Yoast is a great tool that many of us can truly use

  5. Mike
    Mike  • 2 years ago

    Minifying CSS is one thing. Since most CSS files are pretty small, this will have a very subtle effect, if any. It is much more important to reduce the amount of CSS files. On fast connections server requests will significantly slow down your website. Minifying JS often breaks a site or some functions that need javascript. Test your website carefully after activating JS compression.

    • Jorge Villegas
      Jorge Villegas  • 2 years ago

      Excellent information thanks


Check out our must read articles about Technical SEO