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
Allow either 'defer', or 'async' attribute to be added to JavaScript loading in extensions #3078
Allow either 'defer', or 'async' attribute to be added to JavaScript loading in extensions #3078
Conversation
I'd make a slight change to this... Instead of having just the singular versions <script src="file.js" async defer></script> One could assume that if you're applying these to a script tag you know a little about web performance and not blocking the parser. So applying them both would be of great benefit. You'll get good web perf in new browsers and old browsers (back to IE 5 to ie 9) will use the defer attribute. Defer is buggy in a lot of browsers. Async "just works ™" (in most use cases haha) Here is why to use |
wellllllll I'll just hold my horses... I noticed the "attrib" is just a string..... I take back my previous comment haha.. You could in theory pass both in a string since there doesn't seem to be any trimming or anything like that.. |
Thanks, @cdowdy. The only thing is that |
yeah... same for defer too though. The script wont be loaded until after the document has been parsed. |
Here is what I'm referring to when i mentioned defer above defer order buggy If script 1 modifies the dom and script 2 is dependent on script 1 then script 2 can be executed before script 1 is finished and script 2 would have a dependency break (this is <= ie 9 and only mentioned because I believe bopp said bolt corp customers have to support ie 8?) |
Friends don't let friends use IE.
Probably not the greatest example, but close to the problem that I hit that I am trying to solve. My templates defer loading of jQuery and extensions that rely on it b0rk. |
wouldn't it be nice if everyone just all of a sudden started using ie 11 haha... few years ago it was "awww man ie 8 support" now its moved to ie 9 haha
yeah this is where an asset manager would be nice. be it assetic to combine and load all instances of a file to one css or js file or having code for extension template authors which says " if bolt jquery present load jq dependent js.. if not load minified and combined jq and jq dependent." but that isn't an easy task and my php skills are rather procedural programming instead of oop haha |
Absolutely. Big job and someone needs to step up for it. I just wanted to solve problems in the short term with this one. I'll have a better look today/tomorrow at those links and update this as required. |
I'd like if we moved from:
to:
So we can do:
|
How's this now @cdowdy & @bobdenotter |
Looks good ! And like @bobdenotter said earlier having it as an array allows for anything that may be added in the future as well! |
with old parameters
I like it! Good to go, if you ask me. |
Merging in! |
Allow either 'defer', or 'async' attribute to be added to JavaScript loading in extensions
removed magnific popup css from footer, added async defer to app.js
UPDATED
The
addJavaScript()
function now:Produces something similar to:
Changelog
array('late' => true, 'priority' => 10, 'attrib' => 'async defer')