polymer Using external Javascript Libraries with Polymer Lazy Loading

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

  1. Create an HTML file (in this example libraries/turf.html) with the library you want to load:

    <script src="../../bower_components/turf/turf.min.js"></script>
    
  2. Import and use your library when needed:

    doSomething: function(argument, anotherArgument): {
    
        // If library has not been loaded, load it
        if(typeof turf == 'undefined') {
            this.importHref(this.resolveUrl('../libraries/turf.js'), function() {
                // Once the library is loaded, recursively call the function
                this.doSomething(argument, anotherArgument);
            }.bind(this));
    
            return;
        }
        
        // Example usage of a library method
        var point = turf.point([42.123123, -23.83839]);
    }
    


Got any polymer Question?