dynamic-script-loading

Dynamically load Web Components / HTML Imports?

纵然是瞬间 提交于 2019-12-29 06:18:01
问题 How would you go about dynamically loading a web component - in response to a url route change for example? I won't know the requested component ahead of time, so could you simply use JavaScript to write the HTML import and then add the code to the page, or are there implications with this? Perhaps Google Polymer helps? 回答1: Considering just Custom Elements, you can call document.registerElement whenever you want. So from that standpoint, you can dynamically load script using any well known

Dynamically load Web Components / HTML Imports?

 ̄綄美尐妖づ 提交于 2019-12-29 06:17:07
问题 How would you go about dynamically loading a web component - in response to a url route change for example? I won't know the requested component ahead of time, so could you simply use JavaScript to write the HTML import and then add the code to the page, or are there implications with this? Perhaps Google Polymer helps? 回答1: Considering just Custom Elements, you can call document.registerElement whenever you want. So from that standpoint, you can dynamically load script using any well known

How to make a fallback to a whole folder in requireJS

我是研究僧i 提交于 2019-12-13 08:26:00
问题 I understood how I can config in requireJS a fallback for a single file like this: var skin = "christmas"; requirejs.config({ paths: { languagesLocal : [ BaseUrl + skin + '/js/languagesLocal', BaseUrl + "default" + '/js/languagesLocal' ] } }); so incase there is no "chrismas" skin I land to the default script. Now - my question is - How do I make a complete folder to be the fallback folder? so incase one file does not exist in the skin folder - it will have a fallback in another folder. I

How to check if an asynchronously loaded script has finished loading in javascript

白昼怎懂夜的黑 提交于 2019-12-07 03:43:44
问题 Using javascript to asynchronously download another javascript file. I understand that this can be done by inserting a new script tag onto the page with the src attribute set to the file url. I also need to run some code when the script is finished downloading. I've been using yepnope for this and they provide "callbacks" that execute when the script has finished downloading and executing. How is this accomplished? Thanks! 回答1: Most JS loaders do this via injecting an <script> tag to the DOM,

Page speed - any problems with simply using defer attribute?

这一生的挚爱 提交于 2019-12-06 12:54:31
问题 Google recommends scripts should be "deferred", but they do not mention the defer attribute of the <script> tag. I wonder why they don't even mention it, considering it has been around a while. Instead they suggest injecting scripts into the DOM. Is there any particular benefit of this over using the much simpler and cleaner defer attribute? https://developers.google.com/speed/docs/best-practices/payload?csw=1#DeferLoadingJS I gather there are some minor issues with old browsers but I am not

Page speed - any problems with simply using defer attribute?

你离开我真会死。 提交于 2019-12-04 21:38:26
Google recommends scripts should be "deferred", but they do not mention the defer attribute of the <script> tag. I wonder why they don't even mention it, considering it has been around a while. Instead they suggest injecting scripts into the DOM. Is there any particular benefit of this over using the much simpler and cleaner defer attribute? https://developers.google.com/speed/docs/best-practices/payload?csw=1#DeferLoadingJS I gather there are some minor issues with old browsers but I am not supporting anything before IE10 and mostly interested in optimising for mobile browsers. UPDATE: As an

What's the difference between Require.js and simply creating a <script> element in the DOM? [closed]

回眸只為那壹抹淺笑 提交于 2019-12-03 00:11:17
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . What's the difference between using Require.JS amd simply creating a <script> element in the DOM? My understanding of Require.JS is that it offers the ability to load dependencies, but can this not simply be done by creating a <script> element that loads the necessary

What's the difference between Require.js and simply creating a <script> element in the DOM? [closed]

↘锁芯ラ 提交于 2019-12-02 13:56:25
What's the difference between using Require.JS amd simply creating a <script> element in the DOM? My understanding of Require.JS is that it offers the ability to load dependencies, but can this not simply be done by creating a <script> element that loads the necessary external JS file? For example, lets assume I have the function doStuff() , which requires the function needMe() . doStuff() is in the external file do_stuff.js , while needMe() is in the external file need_me.js . Doing this the Require.JS way: define(['need_me'],function(){ function doStuff(){ //do some stuff needMe(); //do some

How to mixin Underscore plugins in RequireJS?

允我心安 提交于 2019-11-30 12:14:41
问题 What is the right way to execute code on Underscore when it gets loaded? I am trying to execute the below code to extend the _ exported namespace automatically when modules require it: _.mixin(_.str.exports()); The docs are a bit vague but I think I put it in the shim init section? I tried the below but I can't even get a breakpoint to hit in the init: require.config({ paths: { jquery: 'libs/jquery/jquery.min', underscore: 'libs/underscore/lodash.min', underscorestring: 'libs/underscore

How to mixin Underscore plugins in RequireJS?

为君一笑 提交于 2019-11-30 02:13:14
What is the right way to execute code on Underscore when it gets loaded? I am trying to execute the below code to extend the _ exported namespace automatically when modules require it: _.mixin(_.str.exports()); The docs are a bit vague but I think I put it in the shim init section? I tried the below but I can't even get a breakpoint to hit in the init: require.config({ paths: { jquery: 'libs/jquery/jquery.min', underscore: 'libs/underscore/lodash.min', underscorestring: 'libs/underscore/underscore.string.min' }, shim: { underscore: { exports: '_' } underscorestring: { deps: ['underscore'],