Async Option #212

Merged
merged 3 commits into from Feb 25, 2013

Projects

None yet

3 participants

@igorlima
Member

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

Thanks!

@itechnology
Contributor

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

@igorlima
Member

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.

@itechnology
Contributor

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

@igorlima igorlima commented on the diff Feb 24, 2013
src/load.js
@@ -347,7 +365,7 @@
if (asset.state === undefined) {
asset.state = PRELOADING;
- asset.onpreload = [];
+ asset.onpreload = [callback];
@igorlima
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] : [];
@igorlima
Member

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
@itechnology
Contributor

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

@igorlima
Member

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?

@itechnology
Contributor

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

@igorlima
Member

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

head
.js({knockout: 'http://knockoutjs.com/downloads/knockout-2.2.1.js', $fn: intermediateFn },
    {angular: 'http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.js', $fn: loadedFn},
    {underscore : 'http://underscorejs.org/underscore-min.js', $async: true, $fn: function(){ console.log('undescore')} },
    )
;

instead of

head
.js({knockout: 'http://knockoutjs.com/downloads/knockout-2.2.1.js'},
    {angular: 'http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.js'},
    {underscore : 'http://underscorejs.org/underscore-min.js', $async: true},
    )
.ready( 'knockout',   intermediateFn )
.ready( 'angular',    loadedFn )
.ready( 'underscore', function() {
  console.log('undescore');
})
;

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
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
pelase..

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