Webkul
Services
Technologies Bagisto QloApps
iOS Android SAP BigCommerce Wix
Trusted by
Samsung Intel Toyota Walmart Disney Nokia Nestlé Decathlon
See all customers
Back to Top
DEV

How to remove JS and CSS in Magento 2 using layout XML

Sometimes, there is a need to remove some static resources(CSS and JS) from a page as there may be conflicts between the theme and the module(extensions) static resources(CSS and JS).

The <remove> tag is used in layout XML under the <head> tag to remove the static resources(CSS and JS files) linked to a page.

Note, that if a static asset is added with a module path (for example Vendor_Module::js/name.js) in the initial layout, you need to specify the module path when removing the asset.

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

If you want to remove static resources(CSS and JS files) on all pages then you need to create a default.xml, the code will be as above only.

For more reference please visit the following link – Layout customizations

. . .

Leave a Comment

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


2 comments

  • luenib
    • Sagar Bathla (Moderator)
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home