-
Notifications
You must be signed in to change notification settings - Fork 648
[Feature Request] Enqueue scripts in footer. #550
Comments
I added support for the script tag attributes 'defer' and 'async' (2081cc1). $app['scripts']->register('some-script', 'script.js', [], ['async' => true]);
$app['scripts']->register('some-script', 'script.js', [], ['defer' => true]); I think this should bring apart from IE < 10 the same performance gains as enqueueing scripts in the footer. What do you think? |
Some background on why we prefer this over rendering in the footer: http://www.growingwiththeweb.com/2014/02/async-vs-defer-attributes.html Browser support looks good: http://caniuse.com/#feat=script-defer |
That's pretty good too, probably good enough for my purposes. The IE <= 9 bug is pretty nasty though, especially if jQuery is affected by it (maybe jQuery has been adjusted since?). On this new feature, is there any way to make the PageKit provided scripts like jQuery use the |
Since the IE <= 9 bug only occurs if scripts depend on each other, I think it is manageable. If you need IE 9 support and depending script with the defer attribute, you can employ for example some kind of browser detection and remove the attribute for IE <= 9. An other option is to load scripts async with Pagekits Asset Mananger. |
Was there a way to get existing scripts to load in a non-blocking fashion? For example, the default theme has 10 blocking script tags in the header. Also, for future visitors, outputting different HTML based on user-agent can cause problems with some reverse-proxies or CDN's, if they do not also serve different HTML for that user-agent. |
Just a heads up the current documentation for the https://pagekit.com/docs/developer/views-templating#working-with-assets <?php $view->script('theme', 'theme:js/theme.js', [], ['defer']) ?> Does not work even though: <?php $view->script('theme', 'theme:js/theme.js', [], ['defer' => true]) ?> works fine. created a pull request for this in the docs |
The <?php $view->script('theme', 'theme:js/theme.js', ['uikit-sticky', 'uikit-lightbox', 'uikit-parallax', 'uikit-datepicker'], ['defer' => true]) ?> Renders: <script src="/app/assets/uikit/js/uikit.min.js?v=cae3"></script>
<script src="/app/assets/uikit/js/components/sticky.min.js?v=cae3"></script>
<script src="/app/assets/uikit/js/components/lightbox.min.js?v=cae3"></script>
<script src="/app/assets/uikit/js/components/parallax.min.js?v=cae3"></script>
<script src="/app/assets/uikit/js/components/datepicker.min.js?v=cae3"></script>
<script src="/packages/pagekit/theme-avion/js/theme.js?v=cae3" defer></script> Note that only the actual |
Re-creating old issue from pre-beta as it seems to still be applicable.
The text was updated successfully, but these errors were encountered: