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 :(

1 Answer 1


In your theme.libraries.yml file add below lines

    '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 :)


Your Answer

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

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