Social Icons

twitterfacebookgoogle pluslinkedinemail

Saturday 13 October 2018

How to add External JS and CSS in Magento 2




Hello Friends,

Sometimes we need to add some external js or css in Magento 2.

So, Here is the code which will help you to add external js or css in your Magento 2 Project.

Please update below path of the file

/app/design/frontend/<ThemeName>/<Theme>/Magento_Theme/layout/default_head_blocks.xml
like
/app/design/frontend/Magento/luma/Magento_Theme/layout/default_head_blocks.xml

if there will no file than please copy from below path and add it in your theme template.
vendor/magento/module-theme/view/frontend/layout/default_head_blocks.xml
Add External Css

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <css src="http://externalcss/external.css" src_type="url"/>
    </head>
</page>

Add External Js

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <script src="http://externaljs/external.js" src_type="url"/>
    </head>
</page>

after add the code in file than please run below commands

php bin/magento setup:static-content:deploy en_US <other language>
php bin/magento cache:flush

Hope This Article will help you to fix your problem.

Thanks
Anant Prajapati
(Magento Certified Developer)

No comments :

Post a Comment

 

Free Advertisement

Free Advertisement

Free Advertisement

Free Advertisement