{"id":1481,"date":"2020-12-24T09:59:43","date_gmt":"2020-12-24T09:59:43","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/remove-js-and-css-in-magento-2-using-layout-xml\/"},"modified":"2025-05-21T17:24:33","modified_gmt":"2025-05-21T11:54:33","slug":"remove-js-and-css-in-magento-2-using-layout-xml","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/remove-js-and-css-in-magento-2-using-layout-xml\/","title":{"rendered":"How to Remove JS and CSS in Magento 2 Using Layout XML"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Is your Magento 2 store having low efficiency and high loading time? Do you want to have&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/speed-up-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">speed optimization of Magento 2<\/a>&nbsp;store? While managing a successful E-commerce store, the store owners have to deal with a lot of problems. One such problem is higher page load time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">While creating a store, you may&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/add-custom-css-and-js-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">add custom CSS and JS in Magento 2<\/a>&nbsp;for attractive layouts and better features. On the other hand, you end up calling numbers of requests and increasing page loading speed. After the page speed analysis, you require to remove JS and CSS in Magento 2 which no longer useful and can improve the page load time. You can also&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/enable-merge-css-javascript-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">enable merge CSS, javascript in Magento 2<\/a>&nbsp;for better performance.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, sometimes the confliction between the theme and module may require you to remove JS and CSS from a page.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Today, I\u2019ve come up with the solution to&nbsp;remove JS and CSS in Magento 2 using layout XML<strong>&nbsp;<\/strong>which can lead to improved load time of the store.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Programmatic Solution to Remove JS and CSS in Magento 2 Using Layout XML<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Create&nbsp;<strong>cms_index_index.xml<\/strong>&nbsp;at&nbsp;<strong>app\/design\/frontend\/[Namespace]\/[theme]\/Magento_Theme\/layout&nbsp;<\/strong>directory and make use of&nbsp;<strong>&lt;remove&gt;<\/strong>&nbsp;tag under the&nbsp;<strong>&lt;head&gt;<\/strong>&nbsp;tag to remove JavaScript and CSS.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\"?>\n\n&lt;page xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n      xsi:noNamespaceSchemaLocation=\"urn:magento:framework:View\/Layout\/etc\/page_configuration.xsd\">\n    &lt;head>\n        &lt;remove src=\"js\/custom.js\"\/>\n        &lt;remove src=\"css\/custom.css\"\/>\n    &lt;\/head>\n&lt;\/page><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s what you need to do to remove JS and CSS in Magento 2 using layout XML.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do not forget to share the post with Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Is your Magento 2 store having low efficiency and high loading time? Do you want to have&nbsp;speed optimization of Magento 2&nbsp;store? While managing a successful&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1481","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1481","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1481"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1481\/revisions"}],"predecessor-version":[{"id":13907,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1481\/revisions\/13907"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1481"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1481"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}