Skip to content

Conversation

@weaverryan
Copy link
Member

@weaverryan weaverryan commented Jan 15, 2021

Fixes #10 - thanks to @dsech for the idea of relying on named Twig arguments (otherwise the new Twig attributes argument is the 4th argument... and rather inconvenient).

This can be configured in 3 different ways:

1) Globally

webpack_encore:
    # ...
    script_attributes:
        defer: true
  1. when when using the Twig functions:
{{ encore_entry_script_tags('my_entry', attributes={
    defer: true
}) }}
  1. Via a new RenderAssetTagEvent

As stated at the bottom of #10 - #10 (comment) - there may be some additional options that would also be nice, but this probably covers the biggest use-case.

NOTE: This also drops support for EOL Symfony versions.

Cheers!

},
"minimum-stability": "dev",
"require": {
"php": ">=7.1.3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably bump to 7.2 as Symfony 4.4 requires it. This would allow you to remove a CI job too :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah indeed!

@weaverryan weaverryan force-pushed the custom_attributes branch 2 times, most recently from 71ae4ba to 8e2ff53 Compare January 15, 2021 16:43
@nicodemuz
Copy link

@weaverryan is it possible to add attributes before the src attribute?

This is a requirement to disable Cloudflare Rocket Loader for a particular script, see:
https://support.cloudflare.com/hc/en-us/articles/200169436-How-can-I-have-Rocket-Loader-ignore-specific-JavaScripts-

The above link mentions The 'data-cfasync' attribute must be added before the 'src' attribute.:

<script data-cfasync="false" src="/javascript.js"></script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow custom script/link tag attributes to be passed

4 participants