Is there any facility to remove js/css specific to browser in magento2 using layout xml ?
4 Answers 4
There is no way to do this in in layout.xml. Here is a list of layout instructions available in Magento 2
http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/xml-instructions.html
If browser compatibility is what you are aiming for, you should take advantage of the modrnizr.js library that comes included in core magento (lib/web/modernizr/modernizr.js)
-
You can force it as a workaround : magento.stackexchange.com/questions/126646/…Franck Garnier– Franck Garnier2017年03月27日 10:31:46 +00:00Commented Mar 27, 2017 at 10:31
Within your own default_head_blocks.xml file do the following:
<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"/>
</head>
</page>
You can add browser specific css like below:
<page>
<head>
<css src="css/ie-9.css" ie_condition="IE 9" />
</head>
</page>
You can remove js and css like below:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<!-- Remove local resources -->
<remove src="css/styles-m.css" />
<remove src="my-js.js"/>
<remove src="Magento_Catalog::js/compare.js" />
<!-- Remove external resources -->
<remove src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css"/>
<remove src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"/>
<remove src="http://fonts.googleapis.com/css?family=Montserrat" />
</head>
Please, refer official document : http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/xml-manage.html#layout_markup_css
-
hi @Pramod, how to add css only for safari browser?Jafar Pinjar– Jafar Pinjar2019年03月01日 11:03:01 +00:00Commented Mar 1, 2019 at 11:03
For removing js files from home page cms.
we need to include the cms_index_index.xml file is our custom theme and by using this layout file can remove the js files form home page in magento 2. Example is here -
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<remove src="varien/form.js"/>
</head>
</page>