ocombe / ocLazyLoad

Lazy load modules & components in AngularJS
https://oclazyload.readme.io
MIT License
2.63k stars 510 forks source link

Load remote files (like from S3 for example) #324

Closed darkmavis1980 closed 8 years ago

darkmavis1980 commented 8 years ago

So this library can load only local files, but it would be nice if you could load also remote javascript libraries, perhaps stored on S3 (but the concept should be applied from any source).

ocombe commented 8 years ago

You can load files from anywhere you want, just use the full url to your file.

darkmavis1980 commented 8 years ago

I did try it, but it simply doesn't work, it doesn't even start the call looking at the network traffic

ocombe commented 8 years ago

Do you have a code example ?

darkmavis1980 commented 8 years ago

What I did it was simply to try to load a module, using the $ocLazyLoad service in this way

$ocLazyLoad.load('https://s3.amazonaws.com/mybucket/module.js');

This simply contains a module (already existing in my application) that append a new service to the app, something like this

angular.module('myapp')

.service('TestService', function(){
  console.log('test');
  this.test = 'hello';
})

.directive('helloWorld', function(TestService){
  return {
    restrict: 'E',
    templateUrl: 'test/template.html',
    controller: function($scope, $element, $attrs){
      $scope.hello = TestService.test;
    }
  }
})

And then I inject the TestService into one of my controllers to see if it's loaded. If I load the file locally, just using $ocLazyLoad.load('test/module.js'); it works fine, I can see the console log, I can see the directive working, no problem. But if I use the same file but on S3, it will just not load anything and my app will throw an error saying that TestService doesn't exists (obviosly).

darkmavis1980 commented 8 years ago

Also I'm using it with Angular 1.5.7

trunghaiy commented 8 years ago

@darkmavis1980 - I can load my module from a remote site. Please make sure server supports CORS.

darkmavis1980 commented 8 years ago

@trunghaiy I'm fairly sure that the CORS permission are fine as we use that S3 for other things, but I'll double check

UprightBeats commented 6 years ago

I know it's pretty old post but just in case if somebody faced the same problem. To make it work you need to remove any links to the library - no matter, local, or remote. The only place where you put it is in $ocLazyLoad.load() function.