Our test app, was ~4MB on initial load, using dynamic import(..) weight is reduced to only ~800KB! Try flow-router-extra now and tell me how it work for you
Update:
To give more inspiration I’ve made an example:
<!--/imports/client/index.html-->
<template name="index">
<h1>Current time is: {{time}}</h1>
</template>
/* /imports/client/index.js */
import moment from 'moment';
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import './index.html';
Template.index.onCreated(function () {
this.time = new ReactiveVar(moment().format('LTS'));
this.timer = null;
});
Template.index.onRendered(function () {
this.timer = Meteor.setInterval(() => {
this.time.set(moment().format('LTS'));
}, 750);
});
Template.index.onDestroyed(function () {
if (this.timer) {
Meteor.clearInterval(this.timer);
this.timer = null;
}
});
Template.index.helpers({
time() {
return Template.instance().time.get();
}
});
To let you see the only required changes before and after dynamic import(...) I’ve made it as diff:
@dirkstevens glad you found it useful and easy to implement.
Share your implementation, and how much of bandwidth you have saved on initial bundle load with dynamic import(..) ?
Hi, check this thread.
I’m not using React, so it’s better to ask there.
But my quick guess - the same way - include modules you need to render a page…
Flow Router is works nice with react components and much more flexible, convenient and advanced than the React Router, with React Router you will have to reinvent the wheels and re-do the simple things that the Flow Router provides out of the box
For example, with RR you have to tinker with url/hash parameters, url-based paginations, absolute/relative paths, etc…
prepare to strain the brain
I think that ReactRouter starred by people who did not know about Iron/Flow Routers
in fact it doesn’t seems to build different bundles… any idea
The app still works but only one js file generated in production.
4 routes of 6 are using dynamics import and they have specific code inside so i expected to get at least 5 bundles
Eh…I didn’t check a count of bundles. But I used bundle visualizer and noticed that bundle size reduced. I have page importing Chart.js lib, which is huge. So I load this page dynamically and when I open the main page there is no Chart.js in the bundle. And when I go to the page with this lib it works well.
You can open “Network” tab in the browser’s Dev Tools, and then select “websocket” and then “Frames” tab, there you will be able to observe what and when actually loaded dynamically.