8

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

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)

16

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

9

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 Mar 1 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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.