-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix script tag replacer #287
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Howdy @eason9487 thanks for that catch. Might you test again with this change f571294 ? Thanks |
@@ -722,6 +722,13 @@ public function async_script_loader_tags( $tag, $handle, $src ) { | |||
return $tag; | |||
} | |||
|
|||
return str_replace( '<script src', '<script async src', $tag ); | |||
// Check if the script has the async attribute already. If so, don't add it again. | |||
$has_async_tag = preg_match( '/^.*async.*$/', $tag ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two async
attributes still occur as this regex pattern cannot match correctly. Maybe consider matching it with a pattern like /\basync\b/
?
Thanks @eason9487, for me it seems like working in Firefox and Chrome... but I replaced it with your solution here e3dd72c Can you check one more time? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix. LGTM.
for me it seems like working in Firefox and Chrome... [...]
Not sure what makes them different. In my testing env, the $tag
content includes two script
tags at a time and is separated by a linebreak char as the following, so the previous regex pattern couldn't match.
<script async src='https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX' id='google-tag-manager-js'></script>
<script id='google-tag-manager-js-after'>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX', { 'send_page_view': false });
</script>
Changes proposed in this Pull Request:
Closes #279
Checks:
Detailed test instructions:
google-tag-manager
script in the sourceAdditional details:
Changelog entry