Comments (4)
@jsms90 The link says "The current state-of-the-art is to put scripts in the tag and use the async or defer attributes. This allows your scripts to be downloaded asap without blocking your browser." at the bottom of the first answer
from week4-3to5.
I know project time is over but I just noticed this issue.
It's not as clear-cut as "use async because it's the current state-of-the-art". For one thing async isn't supported by IE8.
Other answers in that post include some examples of issues with the async property:
<script src="jquery.js" async></script>
<script>jQuery(something);</script>
/*
* might throw "jQuery is not defined" error
* defer will not work either
*/
<script src="jquery.js" async></script>
<script src="jQuery(something).js" async></script>
/*
* might throw "jQuery is not defined" error (no guarantee which script runs first)
* defer will work in sane browsers
*/
The above example is particularly relevant. If dom.js
was downloaded and executed first it would cause all sorts of problems.
<script src="document.getElementById(header).js" async></script>
<div id="header"></div>
/*
* might not locate #header (script could fire before parser looks at the next line)
* defer will work in sane browsers
*/
Putting multiple scripts at the end of the body may not be the best solution but it's definitely the simplest, especially when you have a set of script files that each rely on the last. Async is a great property (especially for below the fold content - both css and js) but shouldn't be used unless you're sure the order of execution doesn't matter.
Further reading (bit old so I'm not sure if it's all still relevant...):
https://www.html5rocks.com/en/tutorials/speed/script-loading/
from week4-3to5.
(I haven't actually read into this that much so I may be completely wrong 😉)
from week4-3to5.
Ah ok thanks 👍 . We started using it because we saw this issue from a previous week (which refers to the same stackoverflow thread) but probs should have actually read into it rather than assuming we should always use it!
from week4-3to5.
Related Issues (20)
- Mobile issues for iOS and safari
- Error for api result
- Accessibility: flying bird gif should have a text alternative
- Searching for mime gives an error
- testing native js methods instead of the code you've written yourself
- Error handling in router function
- empty / unused files in your repo
- Ho oh disappears for a while in the mobile version
- console.logs HOT 1
- unused css?
- pokemon not in library could add an error for that? HOT 2
- Mobile responsiveness on pokeImg class HOT 1
- inconsistent indentation and spacing
- Error message is missing when a user inputs nonsense words
- Amazing project HOT 1
- ash stays the same width at 366px
- Good job thumbs up 3to5! HOT 1
- declare your variables at the top of each file
- pressing enter key after choosing from list should = clicking "Go"
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from week4-3to5.