I have been reading up about using async on script calls in a page header on HTML5 to make script loading not hold up the rest of the page.
So I set out something like
<script src="/includes/js/modernizr-2.6.2.min.js" async></script> <script src="/includes/js/jquery-1.11.0.min.js" async></script> <script src="/includes/js/tinymce/tinymce.min.js" async></script> <script> $( document ).ready(function() { tinymce.init({ mode : "specific_textareas", editor_selector : "mceEditor", plugins: [ "advlist autolink autosave lists link image" ], toolbar1: "insertfile undo redo", image_advtab: true, paste_as_text: true }); /* <other jQuery page specific scripts here too> */ }); </script> But this comes back with various errors:
- JQuery
$is not recognised for the document call. - tinyMCE jquery method
tinymce.initis not recognised
So obviously, I remove the async calls from the script links - and this works, but what's the point of the whole async stuff on page loads, when I can not call any JQuery method or function until jquery.js has to be loaded first and then each .js file also has to be loaded non-asynchronously before the relative methods can be run in the page script (or attached scripts) on document load.
I read a lot about how async is good for AJAX but after changing async to defer I find this also does not solve my problem, returning with the same console errors.
Is there something fundamental that I'm not doing? Or is it that asynchronous script loading is simply not to be done on basic non AJAX page loads?
Edit: With the scripts as they are page loading is roughly +4 seconds, mostly due to tinyMCE with all it's plugins, hence I have attempted to try and load the addons etc, with async...
$( document ).ready(function()not fire until the scripts are all loaded, which in effect is as you say, non-asychronous and so should be in the footer. :-/asynchas worked successfully for me is using it before the closing</body>tag. It allowed my script to execute seamlessly with the AJAX calls.asyncbeing that tinyMCE with all its plugins is quite a slow loader.