0

I am trying to add these CDNs to my custom theme: app\design\frontend\Magento\test\Magento_Theme\layout\default_head_blocks.xml file but it's not working, error : failed to load resource.

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

It says: Refused to load the script 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js'

Thanks in advance

2 Answers 2

0

To add external static resources like CSS, JavaScript, Web fonts (Fontawesome in this case), Please follow the steps below.

  1. Go to this link and copy the CDN URL of Fontawesome.

  2. Find the file app/design/frontend/{Themevendor}/{Themename}/Magento_Theme/layout/default_head_blocks.xml and paste the line below. (The line should be placed in the head tag and the value of src_type should be url.)

<css src="https://use.fontawesome.com/releases/v5.2.0/css/all.css" src_type="url"/>

For details please visit this Magento 2 devdocs link

5
0

For local and external resources, includes are slightly different, note the src_type attribute for external resources.

CSS, Script and other type (link) mentioned here, usually and tags should be sufficient.

<!-- Add local resources -->
    <css src="css/my-styles.css"/>
    <!-- The following two ways to add local JavaScript files are equal -->
    <script src="Magento_Catalog::js/sample1.js"/>
    <link src="js/sample.js"/>
    
<!-- Add external resources -->
    <css src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css"
src_type="url" />
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js" 
src_type="url" />
    <link rel="stylesheet" type="text/css" src="http://fonts.googleapis.com/css?family=Montserrat" 
src_type="url" />

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.