ocLazyLoad icon indicating copy to clipboard operation
ocLazyLoad copied to clipboard

Is it possible to unload a resource?

Open slavafomin opened this issue 10 years ago • 8 comments

Hello! Thanks for this module!

I have a question.

Is it possible to unload a specific resource?

I have two parts of my application that are using two different conflicting stylesheets. I want to use ocLazyLoad to load CSS dynamically by the router for each of these two routes. I will need a way to remove loaded stylesheet when navigating from one route to the other.

Please advise. Thanks!

slavafomin avatar Nov 25 '14 12:11 slavafomin

Hi, there is currently no way to unload something that has been loaded. It would be pointless with angular code because it wouldn't unload the components anyway.

For css it would work if you removed the link tag, but there is no way to do it in ocLazyLoad. You could search for the link tag and remove it yourself with something like that:

$('link[href="/url/to/your/file.css"]').remove();

ocombe avatar Nov 25 '14 13:11 ocombe

Thank you @ocombe for your quick response!

Could you mark this issue as a feature request then?

slavafomin avatar Nov 25 '14 14:11 slavafomin

Sure, but it would be for css / templates only

ocombe avatar Nov 25 '14 14:11 ocombe

That is perfectly fine. I'm not sure that such a function can be useful for AngularJS modules.

slavafomin avatar Nov 25 '14 14:11 slavafomin

For css this would be a real killer feature.

ulrikstrid avatar Dec 12 '14 07:12 ulrikstrid

you can't remove resources after they've been loaded. jquery and angular can't fix this problem. browser manufacturers would have solved this a long time ago if it were that simple.

curlyfro avatar Jan 04 '15 01:01 curlyfro

@curlyfro that is true for JavaScript not CSS. Stylesheets can be disabled via disable attribute or removed and the page will no longer utilize those styles.

My recommendation on this is to not manage stylesheets directly in ocLazyLoad but use a ng-switch at the top of your body tag.

kloy avatar Feb 14 '15 04:02 kloy

anything new on this?

Eduardo-Julio avatar Dec 04 '17 18:12 Eduardo-Julio