New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async Option #212

Merged
merged 3 commits into from Feb 25, 2013

Conversation

Projects
None yet
3 participants
@igorlima
Member

igorlima commented Feb 23, 2013

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!

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Feb 24, 2013

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

Contributor

ghost commented Feb 24, 2013

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

This comment has been minimized.

Show comment
Hide comment
@igorlima

igorlima Feb 24, 2013

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.

Member

igorlima commented Feb 24, 2013

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.

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Feb 24, 2013

Contributor

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

Contributor

ghost commented Feb 24, 2013

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

@@ -347,7 +365,7 @@
if (asset.state === undefined) {
asset.state = PRELOADING;
asset.onpreload = [];
asset.onpreload = [callback];

This comment has been minimized.

@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

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

This comment has been minimized.

Show comment
Hide comment
@igorlima

igorlima Feb 25, 2013

Member

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

Member

igorlima commented Feb 25, 2013

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

itechnology pushed a commit that referenced this pull request Feb 25, 2013

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

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Feb 25, 2013

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

Contributor

ghost commented 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

@igorlima

This comment has been minimized.

Show comment
Hide comment
@igorlima

igorlima Feb 25, 2013

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?

Member

igorlima commented Feb 25, 2013

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?

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Feb 25, 2013

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

Contributor

ghost commented Feb 25, 2013

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

This comment has been minimized.

Show comment
Hide comment
@igorlima

igorlima Feb 25, 2013

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?

Member

igorlima commented Feb 25, 2013

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

This comment has been minimized.

Show comment
Hide comment
@ppker

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

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