How to Load External JS and CSS into Widgets
Was this helpful?
Was this helpful?
This article will demonstrate how to load external JavaScript and CSS into your widgets using our custom code editors.
Loading the external CSS is very straight-forward. You just need to use the CSS @import
.
You can write the following code in your Custom CSS code editor to load and libraries.
Loading the external JavaScript is a bit more tricky because it involves the dependency order.
You can use the $.getScript
method to load external JavaScript files one after the other in your preferred order. The following example loads jquery-bridget, isotope, and masonry-horizontal one by one as the order is critical.
The disadvantage of the previous code snippet is that the preceding JavaScript blocks the next one from loading. (The jquery-bridget blocks the isotope and the isotope blocks masonry-horizontal.) If one of them is a slow asset, your widget rendering could be slower than what you expect.
Thus, we introduce the Stackla.loadJS
method to fix this issue. It starts to load all JavaScript files altogether but executes them in order. The following is the example.
When you click the Fork links in the Code Editor, the generated code will include the usage of Stackla.loadJS
example.
You may be wondering what the public URLs are for your wanted libraries. You may use some of the following resources.
Please note - not all of our code editors allow you to load external JS and CSS. This is currently only available for our Widget editors.
: All of the popular libraries such as Bootstrap, Font Awesome and Animated.css are all available on cdnjs.com.
: RawGit serves raw files directly from GitHub with proper Content-Type headers. That means, you can place your libraries as the GitHub repositories and load it with the rawgit!
Host your files with Nosto's UGC: This feature is not available unless requested, to enable the "CSS/JS Upload" in the Media Library you will need to contact .