9

Is there any facility to remove js/css specific to browser in magento2 using layout xml ?

asked Jan 11, 2016 at 13:14

4 Answers 4

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)

answered Jan 11, 2016 at 15:21
1
18

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>

http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/xml-manage.html#layout_markup_css_remove

answered Jul 1, 2016 at 13:10
10

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

answered Nov 11, 2017 at 15:50
1
  • hi @Pramod, how to add css only for safari browser? Commented Mar 1, 2019 at 11:03
3

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>
answered Jul 29, 2019 at 10:39

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.