Slide 1

Slide 1 text

Dobrý deň, bratia v Bratislave Hello Folks!

Slide 2

Slide 2 text

Kamlesh Chandnani Frontend Engineer : Mobisy Technologies, Bangalore : @_kamlesh_ : kamleshchandnani

Slide 3

Slide 3 text

Progressive Loading… “Less code loaded better, improves performance.”

Slide 4

Slide 4 text

Why?

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Giant Pizza = Main App Bundle Without Code Splitting

Slide 7

Slide 7 text

Pizza Slicer = Code Splitting

Slide 8

Slide 8 text

Pizza Slice = Code Splitted Bundle

Slide 9

Slide 9 text

Checklist ☑ Configure webpack ☑ Use Dynamic Imports ☑ Configure routes to load async bundle

Slide 10

Slide 10 text

const plugins = [ new webpack.optimize.CommonsChunkPlugin({ name: "vendor", minChunks: Infinity, filename: "js/vendor.bundle-[chunkhash:8].js" }), new webpack.optimize.CommonsChunkPlugin({ async: true, children: true, minChunks: 4, filename: "js/commonlazy-[chunkhash:8].js" }), new webpack.optimize.CommonsChunkPlugin({ name: "runtime" }) ]; Checklist ➔ Configure webpack ▢ Use Dynamic Imports ▢ Configure routes to load async bundle

Slide 11

Slide 11 text

const plugins = [ new webpack.optimize.CommonsChunkPlugin({ // extract the vendor chunk into separate chunk name: "vendor", // Name of the chunk minChunks: Infinity, // Creates a chunk but no extra modules are moved into it filename: "js/vendor.bundle-[chunkhash:8].js" // Output filename of the vendor chunk }), new webpack.optimize.CommonsChunkPlugin({ async: true, children: true, minChunks: 4 }), new webpack.optimize.CommonsChunkPlugin({ name: "runtime" }) ];

Slide 12

Slide 12 text

const plugins = [ new webpack.optimize.CommonsChunkPlugin({ name: "vendor", minChunks: Infinity, filename: "js/vendor.bundle-[chunkhash:8].js" }), new webpack.optimize.CommonsChunkPlugin({ async: true, // Only code split bundles will be scanned children: true, // all children of the commons chunk are selected minChunks: 4, // The minimum number of chunks which need to contain a module }), new webpack.optimize.CommonsChunkPlugin({ name: "runtime" }) ];

Slide 13

Slide 13 text

const plugins = [ new webpack.optimize.CommonsChunkPlugin({ name: "vendor", minChunks: Infinity, filename: "js/vendor.bundle-[chunkhash:8].js" }), new webpack.optimize.CommonsChunkPlugin({ async: true, children: true, minChunks: 4 }), new webpack.optimize.CommonsChunkPlugin({ name: "runtime" // to retain the vendor chunks hash when it's not changed // The runtime is the part of Webpack that resolves modules at runtime. If you add a CommonsChunkPlugin with the name of a chunk that does not exist as the name of an entry-point Webpack will extract the runtime, create a chunk by that name and put the runtime in there })];

Slide 14

Slide 14 text

Fact: Sequence of “CommonsChunkPlugin” matters

Slide 15

Slide 15 text

module.exports = { entry: { bundle: "/src/index.js", vendor: ["react", "react-dom"] }, output: { path: "public/build", filename: "js/[name].[chunkhash:8].js", chunkFilename: "js/[name].[chunkhash:8].js", publicPath: "/" }, }

Slide 16

Slide 16 text

module.exports = { entry: { //entry points of an application bundle: "/src/index.js", vendor: ["react", "react-dom"] }, output: { path: "public/build", filename: "js/[name].[chunkhash:8].js", chunkFilename: "js/[name].[chunkhash:8].js", publicPath: "/" }, }

Slide 17

Slide 17 text

module.exports = { entry: { bundle: "/src/index.js", vendor: ["react", "react-dom"] }, output: { // options related to how webpack emits results path: "public/build", filename: "js/[name].[chunkhash:8].js", chunkFilename: "js/[name].[chunkhash:8].js", publicPath: "/" }, }

Slide 18

Slide 18 text

Dynamic Imports Split code via inline function calls within modules. // HOF using dynamic imports with ContextModulePlugin const getChunk = chunkName => import( /* webpackMode: "lazy", webpackChunkName: "[request]" */ `./pages/${chunkName}` //ContextModulePlugin ); Checklist ☑ Configure webpack ➔ Use Dynamic Imports ▢ Configure routes to load async bundle

Slide 19

Slide 19 text

Checklist ☑ Configure webpack ☑ Use Dynamic Imports ➔ Configure routes to load async bundle Loading Async bundles on route visit with React-Router 4

Slide 20

Slide 20 text

react-chunkable yarn add react-chunkable OR npm install react-chunkable --save

Slide 21

Slide 21 text

import ComponentChunk from "react-chunkable"; const getChunk = chunkName => import(/* webpackMode: "lazy", webpackChunkName: "[request]" */ `./pages/${chunkName}`); const HomePage = props => ; class Routes extends PureComponent { render() { return ( } /> ); } }

Slide 22

Slide 22 text

import ComponentChunk from "react-chunkable"; const getChunk = chunkName => import(/* webpackMode: "lazy", webpackChunkName: "[request]" */ `./pages/${chunkName}`); const HomePage = props => ; class Routes extends PureComponent { render() { return ( } /> ); } }

Slide 23

Slide 23 text

import ComponentChunk from "react-chunkable"; const getChunk = chunkName => import(/* webpackMode: "lazy", webpackChunkName: "[request]" */ `./pages/${chunkName}`); const HomePage = props => ; class Routes extends PureComponent { render() { return ( } /> ); } }

Slide 24

Slide 24 text

import ComponentChunk from "react-chunkable"; const getChunk = chunkName => import(/* webpackMode: "lazy", webpackChunkName: "[request]" */ `./pages/${chunkName}`); const HomePage = props => ; class Routes extends PureComponent { render() { return ( } /> ); } }

Slide 25

Slide 25 text

Checklist ☑ Configure webpack ☑ Use Dynamic Imports ☑ Configure routes to load async bundle

Slide 26

Slide 26 text

kamleshchandnani/react-chunkable

Slide 27

Slide 27 text

bit.ly/rc-progressive-loading

Slide 28

Slide 28 text

Say @_kamlesh_ DM Open!