0

I have below code to share on LINE messenger

<div class="line-it-button" data-lang="en" data-type="share-b" data-url="{{ current_path }}" style="display: none;"></div>
<script src="https://d.line-scdn.net/r/web/social-plugin/js/thirdparty/loader.min.js" async="async" defer="defer"></script>

How to include JS using attach_library?

{{ attach_library('https://d.line-scdn.net/r/web/social-plugin/js/thirdparty/loader.min.js') }}

How to attach async="async" defer="defer" ?

Tried using

{{ attach_library('https://d.line-scdn.net/r/web/social-plugin/js/thirdparty/loader.min.js', { 'async' : 'async', 'defer' : 'defer'}) }}

But not working :(

2

In your theme.libraries.yml file add below lines

theme.social:
  js:
    'https://d.line-scdn.net/r/web/social-plugin/js/thirdparty/loader.min.js' : { external: true, defer: true, async: true }

In your twig file

{{ attach_library('theme.social') }}

Clear cache & it works :)

0

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.