-
Notifications
You must be signed in to change notification settings - Fork 16
Dynamic Frontend File Loader
Fred Chien edited this page Nov 2, 2015
·
3 revisions
There are some script and css files required we want to load dynamically when specific react component is being initialized. Lantern provided a decorator @loader to do this work for developer.
import { loader } from 'Decorator';
@loader
class MyComponent extends React.Component {
// ignore ...
}this.loader.script('http://cdn.jsdelivr.net/jquery/2.1.4/jquery.min.js', function() {
// Do something after loaded
});Note that this.loader.script() won't call the callback function on server rendering.
this.loader.script([
'http://cdn.jsdelivr.net/jquery/2.1.4/jquery.min.js',
'cdn.jsdelivr.net/semantic-ui/2.0.7/semantic.min.js'
], function() {
// Do something after loaded
});this.loader.css('http://cdn.jsdelivr.net/semantic-ui/2.0.7/semantic.min.css', function() {
// Do something after loaded
});