How To Remove Unused JS and CSS in Magento 2.x To Speed UP Website Performance

Magento 2.x using multiple set of JS & CSS, while running website These (set of JS & CSS) responsible for website load time, calling numbers of requests and increasing page loading speed,

While calling numbers of requests and increasing page loading speed time. After analysis the page speed, you need to remove unused JS and CSS in Magento 2.x, which no longer useful/support and after removing unused JS and CSS, increase website speed performance as well as page loading speed time decrease.

Remove Unused JS and CSS by using layout XML file

Create XML file cms_index_index.xml inside app/design/frontend/[Namespace]/[theme]/Magento_Theme/layout path

Here removing Unused JS (custom.js, print.js) and CSS (custom.css, print.css) as below

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <remove src="js/print.js"/>
        <remove src="css/print.css"/>
       <remove src="js/custom.js"/>
        <remove src="css/custom.css"/>
    </head>
</page>

Leave a Reply

Your email address will not be published. Required fields are marked *