SlideShare a Scribd company logo
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

Bundle your modules with Webpack
Bundle your modules with WebpackBundle your modules with Webpack
Bundle your modules with Webpack
Jake Peyser
 
Webpack
WebpackWebpack
Webpack
Anjali Chawla
 
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
Derek Willian Stavis
 
Continuous Integration for front-end JavaScript
Continuous Integration for front-end JavaScriptContinuous Integration for front-end JavaScript
Continuous Integration for front-end JavaScript
Lars Thorup
 
Server Side Apocalypse, JS
Server Side Apocalypse, JSServer Side Apocalypse, JS
Server Side Apocalypse, JS
Md. Sohel Rana
 
Vue 淺談前端建置工具
Vue 淺談前端建置工具Vue 淺談前端建置工具
Vue 淺談前端建置工具
andyyou
 
Npm scripts
Npm scriptsNpm scripts
Npm scripts
정윤 김
 
Lecture: Webpack 4
Lecture: Webpack 4Lecture: Webpack 4
Lecture: Webpack 4
Sergei Iastrebov
 
Grunt and Bower
Grunt and BowerGrunt and Bower
Grunt and Bower
George Estebe
 
Build RESTful API Using Express JS
Build RESTful API Using Express JSBuild RESTful API Using Express JS
Build RESTful API Using Express JS
Cakra Danu Sedayu
 
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
k88hudson
 
DotNet MVC and webpack + Babel + react
DotNet MVC and webpack + Babel + reactDotNet MVC and webpack + Babel + react
DotNet MVC and webpack + Babel + react
Chen-Tien Tsai
 
Sails js
Sails jsSails js
NodeWay in my project & sails.js
NodeWay in my project & sails.jsNodeWay in my project & sails.js
NodeWay in my project & sails.jsDmytro Ovcharenko
 
Bower & Grunt - A practical workflow
Bower & Grunt - A practical workflowBower & Grunt - A practical workflow
Bower & Grunt - A practical workflow
Riccardo Coppola
 
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
Ian Bull
 
Cli jbug
Cli jbugCli jbug
Cli jbug
maeste
 
Front-end build tools - Webpack
Front-end build tools - WebpackFront-end build tools - Webpack
Front-end build tools - Webpack
Razvan Rosu
 
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
Giacomo Zinetti
 

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

Presentation Tier optimizations
Presentation Tier optimizationsPresentation Tier optimizations
Presentation Tier optimizations
Anup Hariharan Nair
 
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...
Mikko Ohtamaa
 
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
Timothy Fisher
 
Web Components v1
Web Components v1Web Components v1
Web Components v1
Mike Wilcox
 
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 KnowSpiffy
 
Intro JavaScript
Intro JavaScriptIntro JavaScript
Intro JavaScript
koppenolski
 
Developing High Performance Web Apps
Developing High Performance Web AppsDeveloping High Performance Web Apps
Developing High Performance Web Apps
Timothy Fisher
 
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 ...
tdc-globalcode
 
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...Fabio Franzini
 
Web components - An Introduction
Web components - An IntroductionWeb components - An Introduction
Web components - An Introduction
cherukumilli2
 
Seven Versions of One Web Application
Seven Versions of One Web ApplicationSeven Versions of One Web Application
Seven Versions of One Web Application
Yakov Fain
 
Javascript ui for rest services
Javascript ui for rest servicesJavascript ui for rest services
Javascript ui for rest services
Ioan Eugen Stan
 
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"
Binary Studio
 
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
Karl-Henry Martinsson
 
Mobile and IBM Worklight Best Practices
Mobile and IBM Worklight Best PracticesMobile and IBM Worklight Best Practices
Mobile and IBM Worklight Best PracticesAndrew Ferrier
 
React basic by Yoav Amit, Wix
React basic by Yoav Amit, Wix React basic by Yoav Amit, Wix
React basic by Yoav Amit, Wix
Chen Lerner
 
Java EE8 - by Kito Mann
Java EE8 - by Kito Mann Java EE8 - by Kito Mann
Java EE8 - by Kito Mann
Kile Niklawski
 
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
500Tech
 
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

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

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

APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
Rogerio Filho
 
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptxInternet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
VivekSinghShekhawat2
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
3ipehhoa
 
This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
nirahealhty
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
Gal Baras
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
natyesu
 
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
eutxy
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
JungkooksNonexistent
 
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdfJAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
Javier Lasa
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
laozhuseo02
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
laozhuseo02
 
1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...
JeyaPerumal1
 
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Brad Spiegel Macon GA
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
Arif0071
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
3ipehhoa
 
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
keoku
 
Comptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guideComptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guide
GTProductions1
 
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
ufdana
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Sanjeev Rampal
 

Recently uploaded (20)

APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
 
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptxInternet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
 
This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
 
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
 
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdfJAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
 
1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...
 
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
 
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
 
Comptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guideComptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guide
 
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
 

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?