Reputation:
Okay so I have this page with quite a lot of javascript/jQuery in it. Now the problem is that it sometimes loads and it sometimes doesn't. It eventually gets working after a few refreshes. The page is still a prototype and it's not yet viewable to the users, but i noticed that the problem sometimes spans across the whole website. Does anyone know how to fix this? The login script is jQuery/Ajax based, the contact form is jQuery based and a lot of other design related stuff are based on jQuery as well. Without it, i have a big problemo. All functions are inside document ready functions and all the scrypt tags are using the new html 5 `async="async".
Upvotes: 2
Views: 3722
Reputation: 4479
Sounds like the async
attribute is the problem. If you load jQuery asynchronously, the browser won't wait while it loads. That's great for fast rendering, but if jQuery hasn't loaded by the time your document ready functions in markup execute, they won't work.
Try removing the async
attribute.
Upvotes: 2
Reputation: 35417
Include a jQuery
fallback:
<script type="text/javascript">
if (typeof jQuery == 'undefined')
document.write(unescape("%3Cscript src='/path/jquery' type='text/javascript'%3E%3C/script%3E"));
</script>
Also, since you're using the async=async
attribute you need to run your code when the scripts have finished downloading i.e.: document.load
Upvotes: 3