{"id":9427,"date":"2022-03-14T16:28:40","date_gmt":"2022-03-14T14:28:40","guid":{"rendered":"https:\/\/zeni.cz\/blog\/speed-up-wordpress-websites-by-opzimizing-javascript-and-css\/"},"modified":"2024-07-10T10:55:56","modified_gmt":"2024-07-10T08:55:56","slug":"speed-up-wordpress-websites-by-opzimizing-javascript-and-css","status":"publish","type":"post","link":"https:\/\/zeni.cz\/en\/blog-o-wordpress-woocommerce\/web-optimization\/speed-up-wordpress-websites-by-opzimizing-javascript-and-css\/","title":{"rendered":"Speed Up WordPress Websites by Optimizing JavaScript and CSS"},"content":{"rendered":"<div class=\"gb-container gb-container-4172b90a\">\n\n<p class=\"wp-block-paragraph\" style=\"font-size:16px\"><strong><strong><strong>JavaScript and CSS slow down the page loading because they have to be loaded and executed. Additionally, a lot of JavaScript can have a very negative impact on the performance and responsiveness of the website. Learn how we optimize CSS and JavaScript in WordPress to help speed up your websites.&nbsp;<\/strong><\/strong><\/strong><\/p>\n\n<\/div>\n\n<div class=\"gb-container gb-container-f27fd6ff\">\n\n<h2 class=\"wp-block-heading\">Load Less JavaScript and CSS<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><strong>Consider your choice of plugins and themes<\/strong><\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" style=\"font-size:16px\">Some <strong>plugins and themes <\/strong>in WordPress use a <strong>lot of JavaScript <\/strong>and load lots of CSS, so you should reconsider using them and try to find alternatives. Many of them load Javascript and CSS even on pages that are not affected by the plugin\/theme at all, and thus increase the loading time even where it is not necessary.<\/p>\n\n<\/div>\n\n<div class=\"gb-container gb-container-309b5227\">\n\n<h3 class=\"wp-block-heading\"><strong><strong>Think About the Necessary Functionality<\/strong><\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" style=\"font-size:16px\">When working with WordPress, we always make sure to <strong>load<\/strong> only what is <strong>needed<\/strong> (CSS styles, JavaScript) to prepare the page for <strong>faster loading<\/strong>. For example, we remove unnecessary CSS and JS files.<\/p>\n\n<\/div>\n\n<div class=\"gb-container gb-container-771ac00c\">\n\n<h3 class=\"wp-block-heading\"><strong><strong>Use CSS Instead of JS for Interactive Features<\/strong><\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" style=\"font-size:16px\">If you&#8217;re programming content for WordPress, it&#8217;s a good idea to think about whether JavaScript is really necessary for everything you&#8217;re using JavaScript for. A lot of functionality that used to require JavaScript can now be achieved<strong> with<\/strong> modern <strong>CSS<\/strong> with much less impact on performance. We took advantage of this for example when creating a page for <a target=\"_blank\" href=\"https:\/\/i4comfort.cz\" rel=\"noreferrer noopener nofollow\">i4comfort<\/a> or when creating a <a href=\"https:\/\/zeni.cz\/en\/blog\/custom-menu-for-engeto-without-the-use-of-javascript\/\">Custom Menu For Engeto Without The Use Of JavaScript<\/a>. The website contains a lot of <strong>visual effects<\/strong>, which we included so that they<strong> don&#8217;t slow down<\/strong> the page. You can read more in the article <a href=\"https:\/\/zeni.cz\/en\/blog\/creating-a-website-for-i4comfort\/\">Creating a Website for i4comfort<\/a>.&nbsp;<\/p>\n\n<\/div>\n\n<div class=\"gb-container gb-container-8ff1e9b1\">\n\n<h3 class=\"wp-block-heading\"><strong><strong>Code Handling JS and CSS<\/strong><\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" style=\"font-size:16px\">Always think about where your CSS and JavaScript is needed. It&#8217;s a good idea to divide large CSS files into several smaller ones and load them as needed. We can do the same with JavaScript code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" style=\"font-size:16px\">We mostly use <a target=\"_blank\" href=\"https:\/\/roots.io\/sage\/\" rel=\"noreferrer noopener nofollow\">Sage<\/a> to create themes, which makes such management easier and takes into consideration its importance.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" style=\"font-size:16px\">Read more about <a href=\"https:\/\/zeni.cz\/en\/blog\/serial-killer-why-you-want-a-website-created-on-sage\/\">Why You Want a website created on Sage?<\/a><\/p>\n\n<\/div>\n\n<div class=\"gb-container gb-container-55760527\">\n\n<h2 class=\"wp-block-heading\">Optimize CSS and JavaScript With Minification<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\" style=\"font-size:16px\">Minification <strong>removes<\/strong> everything <strong>that is not necessary<\/strong> from the files (linebreaks, spaces, shortens variable names, etc&#8230;). Text files with CSS and JS are modified to take up less space and <strong>load faster<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"960\" height=\"563\" src=\"https:\/\/zeni.cz\/app\/uploads\/2022\/03\/Difference-between-original-and-minified-code.png\" alt=\"Difference between original and minified code\" class=\"wp-image-7095\" srcset=\"https:\/\/zeni.cz\/app\/uploads\/2022\/03\/Difference-between-original-and-minified-code.png 960w, https:\/\/zeni.cz\/app\/uploads\/2022\/03\/Difference-between-original-and-minified-code-300x176.png 300w, https:\/\/zeni.cz\/app\/uploads\/2022\/03\/Difference-between-original-and-minified-code-768x450.png 768w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><figcaption class=\"wp-element-caption\">Difference between original and minified code<\/figcaption><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\" style=\"font-size:16px\">There are many good <strong>WordPress plugins and themes<\/strong> that minify the code. <strong>In our<\/strong> plugins and themes, we <strong>minify<\/strong> the code while <strong>keeping the original<\/strong> files, which are <strong>easier to modify<\/strong>.&nbsp;<\/p>\n\n<\/div>\n\n<div class=\"gb-container gb-container-f76859b1\">\n\n<h3 class=\"wp-block-heading\"><strong><strong>How To Do It?<\/strong><\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" style=\"font-size:16px\">Your JavaScript and CSS can be minified using <strong>online tools<\/strong> such as <a target=\"_blank\" href=\"https:\/\/closure-compiler.appspot.com\/home\" rel=\"noreferrer noopener nofollow\">Closure Compiler<\/a> or <a target=\"_blank\" href=\"https:\/\/minifycode.com\" rel=\"noreferrer noopener nofollow\">Minify Code<\/a>. JavaScript and CSS that you create for your plugins or insert in customizer can also be minified in this way.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" style=\"font-size:16px\">A better alternative for this is to configure the build of your plugin\/theme. &nbsp;It is possible to use and set up <a target=\"_blank\" href=\"https:\/\/webpack.js.org\" rel=\"noreferrer noopener nofollow\">Webpack<\/a> or tools like <a target=\"_blank\" href=\"https:\/\/www.npmjs.com\/package\/node-minify\" rel=\"noreferrer noopener nofollow\">node-minify<\/a>. This allows you to automatically minify your files, but it requires quite a lot of time and energy, especially if you choose Webpack. That&#8217;s why it&#8217;s better to go for a pre-made solution for your plugin or theme in the form of a starter project, such as <a target=\"_blank\" href=\"https:\/\/roots.io\/sage\/\" rel=\"noreferrer noopener nofollow\">Roots Sage<\/a> for a theme. However, for large projects that you are already working on and it is not easy to migrate them, you need to get help from the tools mentioned above.<\/p>\n\n<\/div>\n\n<div class=\"gb-container gb-container-a0085332\">\n\n<h3 class=\"wp-block-heading\"><strong><strong>How to Use Minification Without Developer Experience?<\/strong><\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" style=\"font-size:16px\">To optimize all the CSS and JS files that your site uses, you can use the <a target=\"_blank\" href=\"https:\/\/wordpress.org\/plugins\/fast-velocity-minify\/\" rel=\"noreferrer noopener nofollow\">Fast Velocity Minify<\/a><strong> plugin<\/strong>. This plugin generates minified CSS and JS files on the first uncached loading&nbsp;of the page which are then loaded in place of the original files on upcoming requests. You can significantly speed up CSS and JavaScript loading this way for plugins and themes that don&#8217;t use minified JavaScript and CSS.<\/p>\n\n<\/div>\n\n<div class=\"gb-container gb-container-bbf240ce\">\n\n<h2 class=\"wp-block-heading\">Less is More<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\" style=\"font-size:16px\">To <strong>speed up<\/strong> your website and thus <strong>increase<\/strong> your <strong>traffic<\/strong>, remember that less is really more in this case. If your site is overloaded with a lot of unnecessary functionality, it&#8217;s clear that this will have an impact on performance.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" style=\"font-size:16px\">There are <strong>many ways<\/strong> to <strong>speed up<\/strong> your website and increase traffic. You can divide <strong>longer pages<\/strong> into <strong>smaller<\/strong> ones,<strong> reduce<\/strong> the amount of unnecessary <strong>images<\/strong>, or aim for <strong>simpler code<\/strong>. We&#8217;ve also written about this in a more detailed article, <a href=\"https:\/\/zeni.cz\/en\/blog\/6-ways-to-improve-the-speed-and-performance-of-your-wordpress-website\/\">6 Ways to Improve the Speed and Performance of Your WordPress Website<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" style=\"font-size:16px\">If you have any questions or need <strong>help with speeding up<\/strong> or optimizing your site, we&#8217;re here for you, don&#8217;t hesitate to <a href=\"https:\/\/zeni.cz\/en\/contact\/\">get in touch<\/a>.&nbsp;<\/p>\n\n<\/div>","protected":false},"excerpt":{"rendered":"<p>JavaScript and CSS slow down the page loading because they have to be loaded and executed. Additionally, a lot of JavaScript can have a very negative impact on the performance and responsiveness of the website. Learn how we optimize CSS and JavaScript in WordPress to help speed up your websites.<\/p>\n","protected":false},"author":29,"featured_media":9428,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","footnotes":""},"categories":[310],"tags":[],"class_list":["post-9427","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-optimization","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"author_meta":{"display_name":"rjurinek","author_link":"https:\/\/zeni.cz\/en\/blog-o-wordpress-woocommerce\/author\/rjurinek\/"},"featured_img":"https:\/\/zeni.cz\/app\/uploads\/2023\/02\/Zrychlenie-webovych-stranok-vo-WordPress-vdaka-optimalizacii-JavaScriptu-a-CSS-5-300x200.jpeg","coauthors":[],"tax_additional":{"categories":{"linked":["<a href=\"https:\/\/zeni.cz\/en\/blog-o-wordpress-woocommerce\/.\/web-optimization\/\" class=\"advgb-post-tax-term\">Web Optimization<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">Web Optimization<\/span>"]}},"comment_count":"0","relative_dates":{"created":"Posted 4 years ago","modified":"Updated 2 years ago"},"absolute_dates":{"created":"Posted on 14.3.2022","modified":"Updated on 10.7.2024"},"absolute_dates_time":{"created":"Posted on 14.3.2022 16:28","modified":"Updated on 10.7.2024 10:55"},"featured_img_caption":"","series_order":"","_links":{"self":[{"href":"https:\/\/zeni.cz\/en\/wp-json\/wp\/v2\/posts\/9427","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zeni.cz\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zeni.cz\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zeni.cz\/en\/wp-json\/wp\/v2\/users\/29"}],"replies":[{"embeddable":true,"href":"https:\/\/zeni.cz\/en\/wp-json\/wp\/v2\/comments?post=9427"}],"version-history":[{"count":2,"href":"https:\/\/zeni.cz\/en\/wp-json\/wp\/v2\/posts\/9427\/revisions"}],"predecessor-version":[{"id":12411,"href":"https:\/\/zeni.cz\/en\/wp-json\/wp\/v2\/posts\/9427\/revisions\/12411"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/zeni.cz\/en\/wp-json\/wp\/v2\/media\/9428"}],"wp:attachment":[{"href":"https:\/\/zeni.cz\/en\/wp-json\/wp\/v2\/media?parent=9427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zeni.cz\/en\/wp-json\/wp\/v2\/categories?post=9427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zeni.cz\/en\/wp-json\/wp\/v2\/tags?post=9427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}