Skip to content
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

duplicate css, js #38

Closed
pruge opened this issue Jul 3, 2014 · 10 comments
Closed

duplicate css, js #38

pruge opened this issue Jul 3, 2014 · 10 comments

Comments

@pruge
Copy link

pruge commented Jul 3, 2014

ui-router
when access /components/:id , add css,js file every time

        .state('components', {
            url: '/components/:id',
            resolve: {
                load: ['$ocLazyLoad','$stateParams', function ($ocLazyLoad, stateParams) {
                    return $ocLazyLoad.load({
                        name: stateParams.id,
                        files: ['some.css', 'some.js']
                    })
                }] 
            },
            templateUrl: 'some.html'
        })

$script prevent duplicate call same js not css

$ocLazyLoadProvider.config({ asyncLoader: $script }); 

I add some code to prevent duplicate css

                var checkCssArr = [];
                cssLoader = cssLoader || function(paths, callback) {
                    if (!_.contains(checkCssArr, paths[0])) {
                        checkCssArr.push(paths[0]);
                    } else {
                        paths = [];
                    }
                    var promises = [];
                    angular.forEach(paths, function loading(path) {
                        promises.push(buildElement('css', path));
                    });
                    $q.all(promises).then(function success() {
                        callback();
                    }, function error(err) {
                        callback(err);
                    });
                }

this method is not accepted jsLoader.

How can I prevent duplicate js, css?

@ocombe
Copy link
Owner

ocombe commented Jul 3, 2014

You're right I should add something to prevent multiple insertions / downloads in the native loaders.
I have an idea for that, I'll code it asap, thanks for the suggestion.

@taz
Copy link
Contributor

taz commented Jul 4, 2014

Hi,

The original PR for css loading I did back on May 10 had duplicate protection baked into the buildElement function :-)

f9dc860

It was just a fairly simplistic approach to track loaded paths...

@ocombe ocombe closed this as completed in 5a5d7f1 Jul 14, 2014
@ocombe
Copy link
Owner

ocombe commented Jul 14, 2014

Feature added in 0.3.1 :)

@pruge
Copy link
Author

pruge commented Jul 16, 2014

ocLazyLoad 0.3.1 update, but still duplicate loading js/css

@ocombe
Copy link
Owner

ocombe commented Jul 16, 2014

Do you use the native loaders ?

@ocombe ocombe reopened this Jul 16, 2014
@pruge
Copy link
Author

pruge commented Jul 16, 2014

yes

@taz
Copy link
Contributor

taz commented Jul 16, 2014

Sorry, had to revert and recommit as github thought I'd replaced the entire file. It made it very difficult to see what I'd actually changed.

Three small changes, one of which should fix the duplicate load issue.

I'll do a PR for it when I've tested it a little more. I need to revisit the last change again in particular as I've had it sitting there locally since 0.2.0 and the whole loading methodology looks to have changed a little bit since I wrote it. I think it's still ok though.

B.

EDIT: Hold that thought, I had another look and I don't think I've accounted for the OP's original scenario. I'll have another look tomorrow if I get a chance. Feel free to test etc in the meantime though. Need sleep!

@ocombe
Copy link
Owner

ocombe commented Jul 16, 2014

Oh nice catch, I didn't think of those use cases !

@ocombe
Copy link
Owner

ocombe commented Jul 22, 2014

Any news on this PR @BenBlazely ?

@taz
Copy link
Contributor

taz commented Jul 22, 2014

PR submitted. I actually thought I'd already submitted it on the weekend... A busy week + a baby with a cold/flu = the memory of a goldfish. :-)

Good thing I hadn't as I found a couple of small issues and have fixed them.

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

No branches or pull requests

3 participants