SlideShare a Scribd company logo
1 of 31
Module Bundling
Agenda
1. Introduction
2. Webpack
3. jspm
Simon Bächler
Web developer at Feinheit
The Problem
• Web sites are turning into Web apps
• Code complexity grows as the site gets bigger
• Developers prefer discrete JS files/modules
• Deployment requires optimized code in just one
or a few HTTP calls
• No standardized import functionality (until now)
<!--[if lt IE 10]>
<script type="text/javascript" src="/static/libs/matchMedia/matchMedia.js"></script>
<script type="text/javascript" src="/static/libs/matchMedia/matchMedia.addListener.js"></script>
<script type="text/javascript" src="/static/libs/1579671/rAF.js"></script>
<![endif]-->
<!-- vendor scripts -->
<script type="text/javascript" src="/static/libs/handlebars/handlebars.min.js"></script>
<script type="text/javascript" src="/static/libs/underscore/underscore.js"></script>
<script type="text/javascript" src="/static/libs/backbone/backbone.js"></script>
<script type="text/javascript" src="/static/libs/backbone-pageable/lib/backbone-pageable.min.js"></script>
<script type="text/javascript" src="/static/libs/jquery-hoverIntent/jquery.hoverIntent.js"></script>
<script type="text/javascript" src="/static/libs/enquire/dist/enquire.min.js"></script>
<script type="text/javascript" src="/static/libs/iCheck/icheck.js"></script>
<script type="text/javascript" src="/static/libs/magnific-popup/dist/jquery.magnific-popup.min.js"></script>
<script type="text/javascript" src="/static/libs/jquery.transit/jquery.transit.js"></script>
<script type="text/javascript" src="/static/libs/jquery.scrollTo/jquery.scrollTo.min.js"></script>
<script type="text/javascript" src="/static/libs/socialcount/dist/socialcount.js"></script>
<script type="text/javascript" src="/static/libs/jQuery-Collapse/src/jquery.collapse.js"></script>
<script type="text/javascript" src="/static/libs/easydropdown/src/jquery.easydropdown.js"></script>
<script type="text/javascript" src="/static/libs/iosslider/_src/jquery.iosslider.min.js"></script>
<script type="text/javascript" src="/static/libs/fastclick/lib/fastclick.js"></script>
<script type="text/javascript" src="/static/libs/moment/min/moment.min.js"></script>
<script type="text/javascript" src="/static/libs/loglevel/dist/loglevel.min.js"></script>
<script type="text/javascript" src="/static/libs/raven-js/dist/raven.min.js"></script>
<!-- end vendor scripts -->
<!-- customized libraries -->
<script type="text/javascript" src="/static/webapp/js/backbone.treemodel.js"></script>
<script type="text/javascript" src="/static/webapp/js/backbone.subset.js"></script>
<script type="text/javascript" src="/static/webapp/js/jquery-ui-1.11.1.custom.min.js"></script>
<script type="text/javascript" src="/static/webapp/js/jquery.ui.datepicker-de-en.js"></script>
<script type="text/javascript" src="/static/webapp/js/moment-locales.js"></script>
<!-- app scripts -->
<script type="text/javascript" src="/static/webapp/js/raven.config.js"></script>
<script type="text/javascript" src="/static/webapp/js/global.js"></script>
<script type="text/javascript" src="/static/webapp/js/footer.js"></script>
<script type="text/javascript" src="/static/webapp/js/breadcrumbs.js"></script>
<script type="text/javascript" src="/static/webapp/js/filters/models.js"></script>
<script type="text/javascript" src="/static/webapp/js/filters/helpers/views.js"></script>
<script type="text/javascript" src="/static/webapp/js/filters/views/singleviews.js"></script>
<script type="text/javascript" src="/static/webapp/js/filters/views/listviews.js"></script>
<script type="text/javascript" src="/static/webapp/js/filters/collections.js"></script>
<script type="text/javascript" src="/static/webapp/js/filters/controller.js"></script>
<script type="text/javascript" src="/static/webapp/js/video.js"></script>
<script type="text/javascript" src="/static/webapp/js/slider.js"></script>
<script type="text/javascript" src="/static/webapp/js/forms.js"></script>
<script type="text/javascript" src="/static/webapp/js/analytics.js"></script>
<script type="text/javascript" src="/static/webapp/js/socialcount.js"></script>
<script type="text/javascript" src="/static/webapp/js/animations.js"></script>
<script type="text/javascript" src="/static/webapp/js/nav/models.js"></script>
<script type="text/javascript" src="/static/webapp/js/nav/views.js"></script>
<script type="text/javascript" src="/static/webapp/js/nav/controller.js"></script>
Javascript Modularization
2010 (Crockford)
var MYAPP = window.MYAPP || {}
MYAPP.Views = {
listView: new ListView(),
detailView: new DetailView()
};
Javascript Modularization
2010 (Crockford)
(function($, MYAPP) {
var app = new MYAPP.App();
app.init($('#container'));
})(jQuery, MYAPP);
True App Modularization
• Code is split up into different modules.
• Dependency graph
• The loading order is irrelevant.
• Code gets executed if all dependencies are
loaded.
• Dependencies can be mocked.
App delivery
• Requests are expensive.
• Deliver as few files as possible.
• Deliver the «above the fold» data first.
• Deliver only code that is needed by the client.
Smart Modularization
common-chunks.js
current-app.js
special-feature1.js special-feature2.js
Assets Versioning
• Adds its hash value to the file name
• Allows for setting long expiration headers
• Requires the HTML to update as well.
• Supported by most popular backends
/static/dist/main-ebf5ec7176585199eb0a.js
Modularization today
CommonJS
var $ = require('jquery');
module.exports = function () {};
Modularization today
AMD
define(['jquery'] , function ($) {
return function () {};
});
Modularization today
ECMA Script 2015
import $ from 'jquery';
function myExample(){};
export default myExample;
Java Script Module Bundlers
• RequireJS (AMD/CommonJS*)
• Browserify (CommonJS/AMD*/ES6*)
• Webpack (CommonJS/AMD/ES6*)
• JSPM / SystemJS (ES6/AMD/CommonJS)
Webpack supports all three
module systems
Configuration based
module.exports = {
context: path.join(__dirname, 'assets'),
entry: {
main: [ 'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./js/main'],
styles: ['./scss/app.scss', './scss/select.less'],
editor: './scss/editor.scss'
},
output: {
path: path.resolve('./assets/build/'),
publicPath: 'http://localhost:3000/assets/build/',
filename: '[name]-[hash].js'
},
devtool: 'source-map',
…
}
loaders: [
{
test: /.jsx?$/,
exclude: /node_modules/,
loaders: ['react-hot', 'babel']},
{
test: /.scss$/,
loader: ExtractTextPlugin.extract(
"css?sourceMap!postcss-loader!sass?" +
"outputStyle=expanded&sourceMap=true")))
},
{
test: /.less/,
loader: ExtractTextPlugin.extract(
"style-loader", "css-loader!less-loader?relative-urls")
},
{
test: /.(png|woff|svg|eot|ttf)$/,
loader: "url-loader?limit=20000"
}
]
Async loading
var films =
document.getElementById('film-gallery');
if(films !== null) {
require.ensure(['lodash'], function(require){
require('./components/FilmApp');
});
}
Hot Module Replacement
DEMO
CSS Live Reload
• No Live Reload with ExtractTextPlugin
• Source maps only with ExtractTextPlugin
(because of WebInspector)
npm is sufficient
npm is the default package manager
and task runner
Production configuration
• Import original configuration
• Overwrite config attributes
• Set NODE_ENV to 'production'
Documentation
jspm.io
jspm / SystemJS
• Package manager (jspm) and module loader
(SystemJS)
• For development: load modules synchronously
• For production: create a bundle
• Support for SPDY (via its own CDN) and possibly
HTTP2
jspm / SystemJS
• In active development
• Uses npm and Github as registries
• A CSS loading plugin is available
• Development != Production environment
DEMO
END OF PART II

More Related Content

What's hot

NodeWay in my project & sails.js
NodeWay in my project & sails.jsNodeWay in my project & sails.js
NodeWay in my project & sails.js
Dmytro Ovcharenko
 

What's hot (20)

Bundle your modules with Webpack
Bundle your modules with WebpackBundle your modules with Webpack
Bundle your modules with Webpack
 
Webpack
WebpackWebpack
Webpack
 
Packing it all: JavaScript module bundling from 2000 to now
Packing it all: JavaScript module bundling from 2000 to nowPacking it all: JavaScript module bundling from 2000 to now
Packing it all: JavaScript module bundling from 2000 to now
 
Continuous Integration for front-end JavaScript
Continuous Integration for front-end JavaScriptContinuous Integration for front-end JavaScript
Continuous Integration for front-end JavaScript
 
Server Side Apocalypse, JS
Server Side Apocalypse, JSServer Side Apocalypse, JS
Server Side Apocalypse, JS
 
Vue 淺談前端建置工具
Vue 淺談前端建置工具Vue 淺談前端建置工具
Vue 淺談前端建置工具
 
Npm scripts
Npm scriptsNpm scripts
Npm scripts
 
Lecture: Webpack 4
Lecture: Webpack 4Lecture: Webpack 4
Lecture: Webpack 4
 
Grunt and Bower
Grunt and BowerGrunt and Bower
Grunt and Bower
 
Build RESTful API Using Express JS
Build RESTful API Using Express JSBuild RESTful API Using Express JS
Build RESTful API Using Express JS
 
Advanced front-end automation with npm scripts
Advanced front-end automation with npm scriptsAdvanced front-end automation with npm scripts
Advanced front-end automation with npm scripts
 
DotNet MVC and webpack + Babel + react
DotNet MVC and webpack + Babel + reactDotNet MVC and webpack + Babel + react
DotNet MVC and webpack + Babel + react
 
Sails js
Sails jsSails js
Sails js
 
NodeWay in my project & sails.js
NodeWay in my project & sails.jsNodeWay in my project & sails.js
NodeWay in my project & sails.js
 
Bower & Grunt - A practical workflow
Bower & Grunt - A practical workflowBower & Grunt - A practical workflow
Bower & Grunt - A practical workflow
 
Node4J: Running Node.js in a JavaWorld
Node4J: Running Node.js in a JavaWorldNode4J: Running Node.js in a JavaWorld
Node4J: Running Node.js in a JavaWorld
 
Cli jbug
Cli jbugCli jbug
Cli jbug
 
Front-end build tools - Webpack
Front-end build tools - WebpackFront-end build tools - Webpack
Front-end build tools - Webpack
 
Nodejs web,db,hosting
Nodejs web,db,hostingNodejs web,db,hosting
Nodejs web,db,hosting
 
One step in the future: CSS variables
One step in the future: CSS variablesOne step in the future: CSS variables
One step in the future: CSS variables
 

Similar to Javascript Bundling and modularization

CTU June 2011 - Things that Every ASP.NET Developer Should Know
CTU June 2011 - Things that Every ASP.NET Developer Should KnowCTU June 2011 - Things that Every ASP.NET Developer Should Know
CTU June 2011 - Things that Every ASP.NET Developer Should Know
Spiffy
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 
Mobile and IBM Worklight Best Practices
Mobile and IBM Worklight Best PracticesMobile and IBM Worklight Best Practices
Mobile and IBM Worklight Best Practices
Andrew Ferrier
 
Going Above JSF 2.0 with RichFaces and Seam
Going Above JSF 2.0 with RichFaces and SeamGoing Above JSF 2.0 with RichFaces and Seam
Going Above JSF 2.0 with RichFaces and Seam
Lincoln III
 

Similar to Javascript Bundling and modularization (20)

Presentation Tier optimizations
Presentation Tier optimizationsPresentation Tier optimizations
Presentation Tier optimizations
 
Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ...
 Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ... Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ...
Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ...
 
Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011
 
Web Components v1
Web Components v1Web Components v1
Web Components v1
 
CTU June 2011 - Things that Every ASP.NET Developer Should Know
CTU June 2011 - Things that Every ASP.NET Developer Should KnowCTU June 2011 - Things that Every ASP.NET Developer Should Know
CTU June 2011 - Things that Every ASP.NET Developer Should Know
 
Intro JavaScript
Intro JavaScriptIntro JavaScript
Intro JavaScript
 
Developing High Performance Web Apps
Developing High Performance Web AppsDeveloping High Performance Web Apps
Developing High Performance Web Apps
 
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
 
Webpack
Webpack Webpack
Webpack
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Web components - An Introduction
Web components - An IntroductionWeb components - An Introduction
Web components - An Introduction
 
Seven Versions of One Web Application
Seven Versions of One Web ApplicationSeven Versions of One Web Application
Seven Versions of One Web Application
 
Javascript ui for rest services
Javascript ui for rest servicesJavascript ui for rest services
Javascript ui for rest services
 
Web Performance Part 4 "Client-side performance"
Web Performance Part 4  "Client-side performance"Web Performance Part 4  "Client-side performance"
Web Performance Part 4 "Client-side performance"
 
IBM Connect 2016 - Break out of the Box
IBM Connect 2016 - Break out of the BoxIBM Connect 2016 - Break out of the Box
IBM Connect 2016 - Break out of the Box
 
Mobile and IBM Worklight Best Practices
Mobile and IBM Worklight Best PracticesMobile and IBM Worklight Best Practices
Mobile and IBM Worklight Best Practices
 
React basic by Yoav Amit, Wix
React basic by Yoav Amit, Wix React basic by Yoav Amit, Wix
React basic by Yoav Amit, Wix
 
Java EE8 - by Kito Mann
Java EE8 - by Kito Mann Java EE8 - by Kito Mann
Java EE8 - by Kito Mann
 
ReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparisonReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparison
 
Going Above JSF 2.0 with RichFaces and Seam
Going Above JSF 2.0 with RichFaces and SeamGoing Above JSF 2.0 with RichFaces and Seam
Going Above JSF 2.0 with RichFaces and Seam
 

More from stbaechler (8)

Distributed apps
Distributed appsDistributed apps
Distributed apps
 
Immutable Libraries for React
Immutable Libraries for ReactImmutable Libraries for React
Immutable Libraries for React
 
Testing React Applications
Testing React ApplicationsTesting React Applications
Testing React Applications
 
User stories schreiben
User stories schreibenUser stories schreiben
User stories schreiben
 
Nested sets
Nested setsNested sets
Nested sets
 
Microformats
MicroformatsMicroformats
Microformats
 
Zeitplanung mit PERT
Zeitplanung mit PERTZeitplanung mit PERT
Zeitplanung mit PERT
 
Bower Paketmanager
Bower PaketmanagerBower Paketmanager
Bower Paketmanager
 

Recently uploaded

( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
nilamkumrai
 
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
nirzagarg
 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
@Chandigarh #call #Girls 9053900678 @Call #Girls in @Punjab 9053900678
 
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men 🔝mehsana🔝 Escorts...
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men  🔝mehsana🔝   Escorts...➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men  🔝mehsana🔝   Escorts...
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men 🔝mehsana🔝 Escorts...
nirzagarg
 

Recently uploaded (20)

Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
 
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
 
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts ServiceReal Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
 
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
 
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
 
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
 
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
 
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men 🔝mehsana🔝 Escorts...
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men  🔝mehsana🔝   Escorts...➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men  🔝mehsana🔝   Escorts...
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men 🔝mehsana🔝 Escorts...
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
 
Microsoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftMicrosoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck Microsoft
 

Javascript Bundling and modularization

  • 4. The Problem • Web sites are turning into Web apps • Code complexity grows as the site gets bigger • Developers prefer discrete JS files/modules • Deployment requires optimized code in just one or a few HTTP calls • No standardized import functionality (until now)
  • 5. <!--[if lt IE 10]> <script type="text/javascript" src="/static/libs/matchMedia/matchMedia.js"></script> <script type="text/javascript" src="/static/libs/matchMedia/matchMedia.addListener.js"></script> <script type="text/javascript" src="/static/libs/1579671/rAF.js"></script> <![endif]--> <!-- vendor scripts --> <script type="text/javascript" src="/static/libs/handlebars/handlebars.min.js"></script> <script type="text/javascript" src="/static/libs/underscore/underscore.js"></script> <script type="text/javascript" src="/static/libs/backbone/backbone.js"></script> <script type="text/javascript" src="/static/libs/backbone-pageable/lib/backbone-pageable.min.js"></script> <script type="text/javascript" src="/static/libs/jquery-hoverIntent/jquery.hoverIntent.js"></script> <script type="text/javascript" src="/static/libs/enquire/dist/enquire.min.js"></script> <script type="text/javascript" src="/static/libs/iCheck/icheck.js"></script> <script type="text/javascript" src="/static/libs/magnific-popup/dist/jquery.magnific-popup.min.js"></script> <script type="text/javascript" src="/static/libs/jquery.transit/jquery.transit.js"></script> <script type="text/javascript" src="/static/libs/jquery.scrollTo/jquery.scrollTo.min.js"></script> <script type="text/javascript" src="/static/libs/socialcount/dist/socialcount.js"></script> <script type="text/javascript" src="/static/libs/jQuery-Collapse/src/jquery.collapse.js"></script> <script type="text/javascript" src="/static/libs/easydropdown/src/jquery.easydropdown.js"></script> <script type="text/javascript" src="/static/libs/iosslider/_src/jquery.iosslider.min.js"></script> <script type="text/javascript" src="/static/libs/fastclick/lib/fastclick.js"></script> <script type="text/javascript" src="/static/libs/moment/min/moment.min.js"></script> <script type="text/javascript" src="/static/libs/loglevel/dist/loglevel.min.js"></script> <script type="text/javascript" src="/static/libs/raven-js/dist/raven.min.js"></script> <!-- end vendor scripts --> <!-- customized libraries --> <script type="text/javascript" src="/static/webapp/js/backbone.treemodel.js"></script> <script type="text/javascript" src="/static/webapp/js/backbone.subset.js"></script> <script type="text/javascript" src="/static/webapp/js/jquery-ui-1.11.1.custom.min.js"></script> <script type="text/javascript" src="/static/webapp/js/jquery.ui.datepicker-de-en.js"></script> <script type="text/javascript" src="/static/webapp/js/moment-locales.js"></script> <!-- app scripts --> <script type="text/javascript" src="/static/webapp/js/raven.config.js"></script> <script type="text/javascript" src="/static/webapp/js/global.js"></script> <script type="text/javascript" src="/static/webapp/js/footer.js"></script> <script type="text/javascript" src="/static/webapp/js/breadcrumbs.js"></script> <script type="text/javascript" src="/static/webapp/js/filters/models.js"></script> <script type="text/javascript" src="/static/webapp/js/filters/helpers/views.js"></script> <script type="text/javascript" src="/static/webapp/js/filters/views/singleviews.js"></script> <script type="text/javascript" src="/static/webapp/js/filters/views/listviews.js"></script> <script type="text/javascript" src="/static/webapp/js/filters/collections.js"></script> <script type="text/javascript" src="/static/webapp/js/filters/controller.js"></script> <script type="text/javascript" src="/static/webapp/js/video.js"></script> <script type="text/javascript" src="/static/webapp/js/slider.js"></script> <script type="text/javascript" src="/static/webapp/js/forms.js"></script> <script type="text/javascript" src="/static/webapp/js/analytics.js"></script> <script type="text/javascript" src="/static/webapp/js/socialcount.js"></script> <script type="text/javascript" src="/static/webapp/js/animations.js"></script> <script type="text/javascript" src="/static/webapp/js/nav/models.js"></script> <script type="text/javascript" src="/static/webapp/js/nav/views.js"></script> <script type="text/javascript" src="/static/webapp/js/nav/controller.js"></script>
  • 6. Javascript Modularization 2010 (Crockford) var MYAPP = window.MYAPP || {} MYAPP.Views = { listView: new ListView(), detailView: new DetailView() };
  • 7. Javascript Modularization 2010 (Crockford) (function($, MYAPP) { var app = new MYAPP.App(); app.init($('#container')); })(jQuery, MYAPP);
  • 8. True App Modularization • Code is split up into different modules. • Dependency graph • The loading order is irrelevant. • Code gets executed if all dependencies are loaded. • Dependencies can be mocked.
  • 9. App delivery • Requests are expensive. • Deliver as few files as possible. • Deliver the «above the fold» data first. • Deliver only code that is needed by the client.
  • 11. Assets Versioning • Adds its hash value to the file name • Allows for setting long expiration headers • Requires the HTML to update as well. • Supported by most popular backends /static/dist/main-ebf5ec7176585199eb0a.js
  • 12. Modularization today CommonJS var $ = require('jquery'); module.exports = function () {};
  • 13. Modularization today AMD define(['jquery'] , function ($) { return function () {}; });
  • 14. Modularization today ECMA Script 2015 import $ from 'jquery'; function myExample(){}; export default myExample;
  • 15. Java Script Module Bundlers • RequireJS (AMD/CommonJS*) • Browserify (CommonJS/AMD*/ES6*) • Webpack (CommonJS/AMD/ES6*) • JSPM / SystemJS (ES6/AMD/CommonJS)
  • 16.
  • 17.
  • 18. Webpack supports all three module systems
  • 19. Configuration based module.exports = { context: path.join(__dirname, 'assets'), entry: { main: [ 'webpack-dev-server/client?http://localhost:3000', 'webpack/hot/only-dev-server', './js/main'], styles: ['./scss/app.scss', './scss/select.less'], editor: './scss/editor.scss' }, output: { path: path.resolve('./assets/build/'), publicPath: 'http://localhost:3000/assets/build/', filename: '[name]-[hash].js' }, devtool: 'source-map', … }
  • 20. loaders: [ { test: /.jsx?$/, exclude: /node_modules/, loaders: ['react-hot', 'babel']}, { test: /.scss$/, loader: ExtractTextPlugin.extract( "css?sourceMap!postcss-loader!sass?" + "outputStyle=expanded&sourceMap=true"))) }, { test: /.less/, loader: ExtractTextPlugin.extract( "style-loader", "css-loader!less-loader?relative-urls") }, { test: /.(png|woff|svg|eot|ttf)$/, loader: "url-loader?limit=20000" } ]
  • 21. Async loading var films = document.getElementById('film-gallery'); if(films !== null) { require.ensure(['lodash'], function(require){ require('./components/FilmApp'); }); }
  • 23. CSS Live Reload • No Live Reload with ExtractTextPlugin • Source maps only with ExtractTextPlugin (because of WebInspector)
  • 24. npm is sufficient npm is the default package manager and task runner
  • 25. Production configuration • Import original configuration • Overwrite config attributes • Set NODE_ENV to 'production'
  • 28. jspm / SystemJS • Package manager (jspm) and module loader (SystemJS) • For development: load modules synchronously • For production: create a bundle • Support for SPDY (via its own CDN) and possibly HTTP2
  • 29. jspm / SystemJS • In active development • Uses npm and Github as registries • A CSS loading plugin is available • Development != Production environment
  • 30. DEMO

Editor's Notes

  1. This talk has two parts Part 2 is much shorter.
  2. This is an actual portrait of me, drawn by the very talented Tika.
  3. From Require.js
  4. Real Website example: 45 Scripts Server side Bundler No explicit dependencies in the scripts. Bundler does not value dependencies. Order of the scripts is important
  5. Global Object, provides a namespace. Everything goes into that object.
  6. Closure Does not pollute global namespace. Dependency on global objects. Unit testing is difficult
  7. Modules define their dependencies. Module loaders build a dependency graph and package the modules accordingly. Dependency Injection.
  8. Modularization competes with delivery over HTTP (1). Think about how you package your assets.
  9. The app should deliver several static files: A common-chunks.js file with all the code that is shared over multiple pages. So it can be cached by the browser. A Js file with code specific for the current app. Code for sections wich are rarely used or needs a big library should be split out into a separate module which is loaded asynchronously on-demand.
  10. e.g. Webpack exports a JSON with the asset targets and file names. Django has a library called django-webpack-loader that reads that JSON and adds the data into the HTML template. It also waits for Webpack to complete building if necessary.
  11. CommonJS: Introduced with Node.js. Designed for synchronous loading. (Browserify) Problem: It doesn’t work in the browser.
  12. Asynchronous Module Definition (AMD): Designed for asynchronous loading. Runs a callback when ready. A bit like $(function(){}); Require.js, Angular.js UMD: Universal Module Definition (for libraries)
  13. CommonJS: Designed for synchronous loading. (Browserify) Asynchronous Module Definition (AMD): Designed for asynchronous loading. Require.js, Angular.js UMD: Universal Module Definition (for libraries)
  14. Currently 3 popular bundlers. JSPM is very new. With plugins
  15. Survey in August 2015. Half the people are using a module bundler. Ashley Nolan http://ashleynolan.co.uk/blog/frontend-tooling-survey-2015-results
  16. By Tobias Koppers. This is a free-time project. MIT license
  17. Compared to Browserify it can split the code into multiple modules. Component structure: CSS and Image are also part of a component and can therefore be included. CSS load order is not guaranteed if CSS is embedded in the Javascript files. You can extract the CSS into its own file.
  18. The configuration is a Javascript object. Because it is a CommonJS module, configurations can be extended by other modules. E.g. a production config can just import the default configuration and overwrite the necessary properties.
  19. Assets are loaded using a loader. The test property is a regex that is applied to all the files in a directory. Loaders can be chained and passed attributes. The first loader tests for js and jsx files and uses babel to parse ES6 code. SCSS and LESS loaders can work in the same project. (3rd party library used less). URL loader copies the files if they are less than 20kB. Otherwise it embeds them. Copied files can be given a hash-name.
  20. Automatically creates separate bundles for parts of the app that are only needed on demand. Here the FilmApp is a large React application that is only loaded if an element with the ID 'film-gallery' is present in the DOM.
  21. Webpack Dev server stores files in memory.
  22. You have to chose between live reload and source maps. Web inspector only shows source maps for css if the source file is a CSS file.
  23. Bower can be used, but it is not necessary. No Gulp required. (Gulp can be used but makes the builds slower.) NPM is the default package manager (and task runner)
  24. Have a separate config file for production builds. Replace destination paths, add ugilfyJS NODE_ENV environment variable is used by React to remove debugging statements.
  25. jspm is a package manager for the SystemJS universal module loader, built on top of the dynamic ES6 module loader SystemJS is a Polyfill for the System specification
  26. There is no Javascript watch and compiling tasks in development.
  27. jspm Version 0.16.0 was released on 18. August. jspm Version 0.16.6 was released on 19. September. 7 Releases in one Month. SystemJS: 6 releases in the last two weeks. Sass loader plugin is still in alpha stage.
  28. Any questions so far?