Async Option #212

merged 3 commits into from Feb 25, 2013


None yet

3 participants


The idea here is about our discuss in the Issue #204.
With this property, we can choose if a script will load in parallel and execute as soon as possible.
The option default is false.
You can see an example at js fiddle



Not gonna pull this now, but gonna see exactly what changes are here. I like the ideas, but need to analyze the code in detail before deciding on anything


It probably seems to change a lot more things than just the async option, because I modify the api.ready method to accept some array as a key.
I like the idea to have an array as a parameter.


I really like the idea of the array on api.ready

@igorlima igorlima commented on the diff Feb 24, 2013
@@ -347,7 +365,7 @@
if (asset.state === undefined) {
asset.state = PRELOADING;
- asset.onpreload = [];
+ asset.onpreload = [callback];
igorlima Feb 24, 2013 Member

I modified this line because the callback argument wasn't used before. So... I pushed the callback in asset.onpreload and it can be called in the onPreload method.

I think this line would be better if it be refactored like the code bellow:

asset.onpreload = callback ? [callback] : [];

I did some extra tests in features/async-option branch.
Also, I modified the line 368 which is commented in the diff.

@itechnology itechnology merged commit 37983d7 into headjs:master Feb 25, 2013

Pulled your request, my files where starting to get a bit too much out of sync so decided to pull before it's too late :)
Just renamed $async to async

Will give this some thorough testing tomorrow


Hi, if we renamed $async to async, it's not possible to have a label as 'async'. Using the character '$' means it's an option of HeadJS lib. What you think about that?


Ahh ...reserved name, hein ?
Will test tomorrow ..but not a big fan of $ signs here. ..maybe isAsync: true

Did a few other minor changes, and alot of cleanup to make JSHint happy


If we decide to use some sign, we can give the lib more features like suggestion in Issue #157:

.js({knockout: '', $fn: intermediateFn },
    {angular: '', $fn: loadedFn},
    {underscore : '', $async: true, $fn: function(){ console.log('undescore')} },

instead of

.js({knockout: ''},
    {angular: ''},
    {underscore : '', $async: true},
.ready( 'knockout',   intermediateFn )
.ready( 'angular',    loadedFn )
.ready( 'underscore', function() {

As you see, we need less code right?
You said you're not fan of $ sign, but we can use something that give us possibility to add more features.
What you think?

ppker commented Jul 2, 2015
<script src="/js/head.js" type="text/javascript" data-headjs-load="/js/init.js"></script>

this "data-headjs-load" property
how to write the init.js?
can you give me a example? how to write the init.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment