Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
fixes #3
  • Loading branch information
scottjehl committed Apr 7, 2015
1 parent e082675 commit 16886fc
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ Then call it by passing it a JavaScript URL:
</head>
```

## Why not just use `<script src="..." async defer>`?

The `async` and `defer` attributes enjoy broad browser support. They're great options when all you need to do is load a script for all users, ideally in a non-blocking manner. The limitations with these attributes are:

1. Some older browsers do not support `async` ([though defer has broader support so it's typically not a problem](https://www.igvita.com/2014/05/20/script-injected-async-scripts-considered-harmful/))
2. There's no way to use these attributes to *conditionally* load a script, depending on feature or environmental conditions.

Number 2 above is the main reason we use `loadJS`. Say you want to check if `querySelector` is supported before requesting your entire DOM framework and UI scripting - you'll need to use a script loader to do that. But again, if you just want to load a script unconditionally, these attributes are recommended.

## Limitations

`loadJS` does nothing to manage execution order of requested scripts, so we do not advise using it to load multiple javascript files that depend on one another. It simply fetches a script and executes it as soon as possible. You can certainly use `loadJS` to load multiple scripts as long as those scripts are designed to execute independently of any other scripts being loaded by `loadJS`.
Expand Down

0 comments on commit 16886fc

Please sign in to comment.