Cookies setting

Cookies help us enhance your experience on our site by storing information about your preferences and interactions. You can customize your cookie settings by choosing which cookies to allow. Please note that disabling certain cookies might impact the functionality and features of our services, such as personalized content and suggestions. Cookie Policy

Cookie Policy
Essential cookies

These cookies are strictly necessary for the site to work and may not be disabled.

Information
Always enabled
Advertising cookies

Advertising cookies deliver ads relevant to your interests, limit ad frequency, and measure ad effectiveness.

Information
Analytics cookies

Analytics cookies collect information and report website usage statistics without personally identifying individual visitors to Google.

Information
mageplaza.com

How to Enable Merge CSS, JavaScript in Magento 2

Vinh Jacker | 06-22-2016

Enable Merge CSS, JavaScript

All separated CSS files and CSS files and JavaScript Files can be merged into one single or condensed file that helps to optimize your site and reduce page loading time. After merging, a merged CSS file or Script Files will be shown without line breaks and be disallowed to edit the file. To enable Merge CSS, JavaScript in Magento 2 you can follow some simple steps which are given bellow.

How to Enable Merge CSS, JavaScript in Magento 2

Facts of page loading speed that you need to know

  • More than 45% of visitors will not purchase the product if they experience an eCommerce site that loads slower than expected (Unbounce).
  • 53% of mobile site visitors tend to leave a page when having to wait more than three seconds (Akamai).
  • A decrease of 0.1 second in page load time can increase retail customer engagement by 5.2% (UnbounceGoogle, Fifty-Five, and Deloitte).

Hence, it is essential that your page will perform at its best speed. Enabling Merge CSS, JavaScript in Magento 2 can be your first step in this site optimization process.

Discover Site Speed Optimization services

To merge CSS files in Magento 2

  • On the Admin panel, click Stores. In the Settings section, select Configuration.
  • Select Developer under Advanced in the panel on the left
  • Open the CSS Settings section, and continue with following:

How to Enable Merge CSS, JavaScript

  • In the Merge CSS Files field, select Yes
  • When complete, click Save Config.

To merge JavaScript files in Magento 2

  • On the Admin panel, click Stores. In the Settings section, select Configuration.
  • Select Developer under Advanced in the panel on the left
  • Open the JavaScript Settings section, and continue with following:

How to Enable Merge CSS, JavaScript

  • In the Merge JavaScript Files field, select Yes
  • When complete, click Save Config.

To merge CSS and JavaScript files programmatically

Once your website is set to the production mode, the only way to enable JavaScript or CSS is using the CLI. Run the following command to merge JavaScript/ CSS from the CLI.

Magento 2.2.X and 2.3.X

bin/magento config:set dev/css/merge_css_files 1
bin/magento cache:clean

Magento 2.0.X and 2.1.X

UPDATE core_config_data SET value = 1 WHERE path = 'dev/css/merge_css_files';

Using n98-magerun2 for Magento 2.1.X, 2.2.X and 2.3.X

n98-magerun2.phar config:store:set dev/css/merge_css_files 1
n98-magerun2.phar cache:clean
Environment configuration
...
'js' => [
   'merge_files' => '1',
   'minify_files' => '1',
],
'css' => [
    'minify_files' => '1',
    'merge_css_files' => '1',
],
...

Increasing your website loading speed is the first step to increasing conversion rates and boosting sales, and it can be done by enabling Merge CSS, JavaScript in Magento 2. Hopefully the statistics will give you another insight into this matter, and the guidelines show you how to deal with it. You can get your site performance audit and find solutions for your store here. Leave comments below to share with us your results!

Related Post

x
    Jacker

    With over a decade of experience crafting innovative tech solutions for ecommerce businesses built on Magento, Jacker is the mastermind behind our secure and well-functioned extensions. With his expertise in building user-friendly interfaces and robust back-end systems, Mageplaza was able to deliver exceptional Magento solutions and services for over 122K+ customers around the world.



    Related Post

    Website Support
    & Maintenance Services

    Make sure your store is not only in good shape but also thriving with a professional team yet at an affordable price.

    Get Started
    mageplaza services