SlideShare una empresa de Scribd logo
1 de 37
Loading Javascript
Szabolcsi-Tóth Szabolcs
Senior Frontend Developer at Ustream.
@_Nec
nec@shell8.net
Loading Javascript
These slides are
not about:
detailing defer/FIF js
embedding on site
or putting the js after the
body or in the head
These slides are
supposed to be
about:
detailing why static js
loading, packaging and
building leads to nowhere
on the long run
and a possible solution
Inline scripting
● Quick sandboxing
● Small demos
● Learning
● Testing http://www.flickr.com/photos/pfly/399346124/
Javascript Files
● Separate code from markup
● Serve assets from a server
http://www.flickr.com/photos/seiho/2183406722/
Code organization
Webapp complexity
increases
Loadtime becomes
an issue :(
Use of functions,
classes, modules
Codebase grows
http://www.flickr.com/photos/chiotsrun/4390949664/
Code compilation / build
Much less http requests
Tools:
● concatenation
● uglify / yuicompressor
http://www.flickr.com/photos/halfbisqued/2353845688/
Code compilation / build
Compile all the js that the
current page might need:
Several smaller files
Compile all js that we need:
One huge file
Create js groups according to
page needs
http://www.flickr.com/photos/halfbisqued/2353845688/
Code compilation / build
Compile all the js that the
current page might need:
Several smaller files
Compile all js that we need:
One huge file
Create js groups according to
page needs
What is the problem with that?
http://www.flickr.com/photos/halfbisqued/2353845688/
Take any page, coded, optimized, built,
deployed
Uh-Oh.. The Product / UX / Design division
enters the room!
The new killer feature, that saves us!
Click here to
close
Code compilation / build
The given feature is used on the page,
or
The visitor might use it on the page
"the current page might need"
One page gets n+1 new feature:
The js compiled group for that page grows even more
heavy
Do we really need it onLoad?
Lots of unused code, that waits for the user:
overhead, slows load time.
http://www.flickr.com/photos/halfbisqued/2353845688/
Async loading!
Load only the most necessary js onLoad!
Then, for every feature the user wants,
load the js runtime.
http://www.flickr.com/photos/thenationalguard/8029811025/
● Feature based code, not page based
code
● Small lag in UX, but faster page start
● Loose module coupling, better code
Code compilation / build
Compile all the js that the
current page might need:
Several smaller files
Compile all js that we need:
One huge file
Create js groups according to
page needs
And what is the problem with that?
http://www.flickr.com/photos/halfbisqued/2353845688/
Dependency handling
The problem with predefined js
groups:
http://www.flickr.com/photos/wongjunhao/2761709029/
● add js by planned use
(add a feature, that can be used)
● add js by failsafe use
("this might come handy" or "make sure to have
this")
● group is built at deploy
Dependency handling
The group is created for a
planned usage
The group contents has nothing
to do with the real functioning
site or app
http://www.flickr.com/photos/wongjunhao/2761709029/
Dependency handling
Let the js codebase define it's own
dependency
Here come the modules!
AMD
(Asynchronous Module Definition)
Designed for the
web
CommonJS
Designed for the
server (nodejs)
http://www.flickr.com/photos/wongjunhao/2761709029/
Dependency handling
AMD structure
define (
// optional, used in build code
'moduleName',
// dependencies
['modules/Module1', 'modules/Module2'],
// module definition
function (module1, module2) {
});
http://www.flickr.com/photos/wongjunhao/2761709029/
Async loading + Modules
Module loader
a javascript utility, that:
● handles module definitions and
requirements
● loads modules from a remote
server
require.js, curl.js, etc
http://www.flickr.com/photos/redux/4298421692/
Async loading + Modules
Require.js example
http://www.flickr.com/photos/redux/4298421692/
Every dependency starts a new request
Lots of requests - not very good
Async loading + Modules
Need fewer requests?
Introduce async packaging!
http://www.flickr.com/photos/redux/4298421692/
Request and load packaged javascripts
async, instead of each file.
But how will the client know of the
available package list?
Async loading + Modules
Possible solution:
expose the built package list, and contents
to the client
http://www.flickr.com/photos/redux/4298421692/
Why not?
In case of a large codebase, this can be an
uncomfortably large amount of data. Also,
exposes the whole codebase to the client.
Async loading + Modules
Another problem with pre-built packages,
prepared for async load:
Overlapping dependencies are inevitable
http://www.flickr.com/photos/redux/4298421692/
Pack_1 Pack_2 Pack_3
Foo.js Foo.js
Bar.js Bar.js
Either package every common
dependency, every time it's needed...
Async loading + Modules
Overlapping dependencies...
Or put those commons to the page
onLoad
http://www.flickr.com/photos/redux/4298421692/
Pack_1 Pack_2 Pack_3
Pack_onLoad Foo.js Bar.js
Codebase at onLoad starts grow fast,
getting slower pageload :(
Async loading + Modules
So...
http://www.flickr.com/photos/redux/4298421692/
Either we have lots of
requests
Or big files, with massive
redundancy and
duplicated code.
Pack_1
Pack_2
Pack_3
Foo.js
Foo.js
Bar.js
Bar.js
Async loading + Modules
Are we keep circling around the
same issue?
http://www.flickr.com/photos/redux/4298421692/
JS Module Server
Time to rethink the way of
serving javascript instead of
loading it as a fully static asset.
Put the dependency handling to
the server side.
http://www.flickr.com/photos/alca_impenne/4295937972/
JS Module Server
Credit where it's due!
Malte Ubl & John Hjelmstad
http://www.youtube.com/watch?v=mGENRKrdoGY
Two guys at Google/Gmail
http://www.flickr.com/photos/alca_impenne/4295937972/
JS Module Server
Request just one module, the
server finds it's dependencies,
packs and serves.
/js/+app/Foo.js
On the client side, we keep track
of what modules have been
requested already.
http://www.flickr.com/photos/alca_impenne/4295937972/
JS Module Server
At the next requested module, we
tell the server which modules
were requested already
(note: not all the received, just the requested)
These are "subtracted" from the
request
/js/+app/Bar-app/Foo.js
http://www.flickr.com/photos/alca_impenne/4295937972/
JS Module Server
/js/+app/Bar-app/Foo.js
The server takes the requested module
dependencies, and subtracts all those, that
have been served for the client already.
The new package only contains code
that haven't been loaded by the client.
http://www.flickr.com/photos/alca_impenne/4295937972/
JS Module Server
/js/ +app/Bar - app/Foo.js
No redundant modules.
app/Bar
class/Lorem
class/Ipsum
class/Sit
...
app/Foo
class/Lorem
class/Sit
class/Dolor
...
app/Bar
class/Ipsum
...
JS Module Server
Providing solution for:
" lots of requests "
Thinking in feature-oriented code, instead of the page-
oriented code, these async loads can refer to only the
requested feature. One request per feature.
" big files, with massive redundancy and duplicated code "
Only that code is packaged, that haven't been served
already.
http://www.flickr.com/photos/alca_impenne/4295937972/
JS Module Server
Additional gains
● full i18n support (can require groups by locale)
● cacheable urls
● sourcemap support (via uglify2)
● the full codebase is loaded by the
server, it can run tasks on it, debug
output, etc. (strip all console.* for example)
● could handle CSS later (with supporting
preprocessors like SASS/LESS)
http://www.flickr.com/photos/alca_impenne/4295937972/
JS Module Server
● Parallel requests
(add a counter-callback parameter,
which determines the right parse order
for the module loader, like JSONP)
● Handle browser cache properly
(this one is a tricky one, but we're on
the way. Changing the url is 100% sure,
but If-Modified-Since would be nicer)
Things to be done
http://www.flickr.com/photos/alca_impenne/4295937972/
JS Module Server
Things to be done
● Put it to production
(soon on Ustream)
● Open source it
(soon on GitHub)
http://www.flickr.com/photos/alca_impenne/4295937972/
Questions?
Thank you!

Más contenido relacionado

La actualidad más candente

Link. apache wicket [santi caltabiano]
  Link. apache wicket [santi caltabiano]  Link. apache wicket [santi caltabiano]
Link. apache wicket [santi caltabiano]santi caltabiano
 
Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"Fwdays
 
jQuery Conference Boston 2011 CouchApps
jQuery Conference Boston 2011 CouchAppsjQuery Conference Boston 2011 CouchApps
jQuery Conference Boston 2011 CouchAppsBradley Holt
 
Testing Mobile JavaScript
Testing Mobile JavaScriptTesting Mobile JavaScript
Testing Mobile JavaScriptjeresig
 
Voiture tech talk
Voiture tech talkVoiture tech talk
Voiture tech talkHoppinger
 
Blazor - An Introduction
Blazor - An IntroductionBlazor - An Introduction
Blazor - An IntroductionJamieTaylor112
 
S/W Design and Modularity using Maven
S/W Design and Modularity using MavenS/W Design and Modularity using Maven
S/W Design and Modularity using MavenScheidt & Bachmann
 
Frontend Monoliths: Run if you can!
Frontend Monoliths: Run if you can!Frontend Monoliths: Run if you can!
Frontend Monoliths: Run if you can!Jonas Bandi
 
Getting started with spfx
Getting started with spfxGetting started with spfx
Getting started with spfxJenkins NS
 
Apache Flex and the imperfect Web
Apache Flex and the imperfect WebApache Flex and the imperfect Web
Apache Flex and the imperfect Webmasuland
 
Web worker in your angular application
Web worker in your angular applicationWeb worker in your angular application
Web worker in your angular applicationSuresh Patidar
 
Play Framework: The Basics
Play Framework: The BasicsPlay Framework: The Basics
Play Framework: The BasicsPhilip Langer
 
Enterprise makeover. Be a good web citizen, deliver continuously and change y...
Enterprise makeover. Be a good web citizen, deliver continuously and change y...Enterprise makeover. Be a good web citizen, deliver continuously and change y...
Enterprise makeover. Be a good web citizen, deliver continuously and change y...Mateusz Kwasniewski
 
CollabSphere 2018 - Java in Domino After XPages
CollabSphere 2018 - Java in Domino After XPagesCollabSphere 2018 - Java in Domino After XPages
CollabSphere 2018 - Java in Domino After XPagesJesse Gallagher
 
2012 04-19 theory-of_operation
2012 04-19 theory-of_operation2012 04-19 theory-of_operation
2012 04-19 theory-of_operationbobwolff68
 
Engage 2015 - 10 Mistakes You and Every XPages Developer Make. Yes, I said YOU!
Engage 2015 - 10 Mistakes You and Every XPages Developer Make. Yes, I said YOU!Engage 2015 - 10 Mistakes You and Every XPages Developer Make. Yes, I said YOU!
Engage 2015 - 10 Mistakes You and Every XPages Developer Make. Yes, I said YOU!Serdar Basegmez
 
Joomladay Es 2009 - Nooku Framework
Joomladay Es 2009  - Nooku FrameworkJoomladay Es 2009  - Nooku Framework
Joomladay Es 2009 - Nooku FrameworkNooku
 
Create ReactJS Component & publish as npm package
Create ReactJS Component & publish as npm packageCreate ReactJS Component & publish as npm package
Create ReactJS Component & publish as npm packageAndrii Lundiak
 

La actualidad más candente (20)

Link. apache wicket [santi caltabiano]
  Link. apache wicket [santi caltabiano]  Link. apache wicket [santi caltabiano]
Link. apache wicket [santi caltabiano]
 
Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"
 
jQuery Conference Boston 2011 CouchApps
jQuery Conference Boston 2011 CouchAppsjQuery Conference Boston 2011 CouchApps
jQuery Conference Boston 2011 CouchApps
 
Testing Mobile JavaScript
Testing Mobile JavaScriptTesting Mobile JavaScript
Testing Mobile JavaScript
 
Review Adobe Wallaby
Review Adobe WallabyReview Adobe Wallaby
Review Adobe Wallaby
 
Voiture tech talk
Voiture tech talkVoiture tech talk
Voiture tech talk
 
Blazor - An Introduction
Blazor - An IntroductionBlazor - An Introduction
Blazor - An Introduction
 
Refactoring to a SPA
Refactoring to a SPARefactoring to a SPA
Refactoring to a SPA
 
S/W Design and Modularity using Maven
S/W Design and Modularity using MavenS/W Design and Modularity using Maven
S/W Design and Modularity using Maven
 
Frontend Monoliths: Run if you can!
Frontend Monoliths: Run if you can!Frontend Monoliths: Run if you can!
Frontend Monoliths: Run if you can!
 
Getting started with spfx
Getting started with spfxGetting started with spfx
Getting started with spfx
 
Apache Flex and the imperfect Web
Apache Flex and the imperfect WebApache Flex and the imperfect Web
Apache Flex and the imperfect Web
 
Web worker in your angular application
Web worker in your angular applicationWeb worker in your angular application
Web worker in your angular application
 
Play Framework: The Basics
Play Framework: The BasicsPlay Framework: The Basics
Play Framework: The Basics
 
Enterprise makeover. Be a good web citizen, deliver continuously and change y...
Enterprise makeover. Be a good web citizen, deliver continuously and change y...Enterprise makeover. Be a good web citizen, deliver continuously and change y...
Enterprise makeover. Be a good web citizen, deliver continuously and change y...
 
CollabSphere 2018 - Java in Domino After XPages
CollabSphere 2018 - Java in Domino After XPagesCollabSphere 2018 - Java in Domino After XPages
CollabSphere 2018 - Java in Domino After XPages
 
2012 04-19 theory-of_operation
2012 04-19 theory-of_operation2012 04-19 theory-of_operation
2012 04-19 theory-of_operation
 
Engage 2015 - 10 Mistakes You and Every XPages Developer Make. Yes, I said YOU!
Engage 2015 - 10 Mistakes You and Every XPages Developer Make. Yes, I said YOU!Engage 2015 - 10 Mistakes You and Every XPages Developer Make. Yes, I said YOU!
Engage 2015 - 10 Mistakes You and Every XPages Developer Make. Yes, I said YOU!
 
Joomladay Es 2009 - Nooku Framework
Joomladay Es 2009  - Nooku FrameworkJoomladay Es 2009  - Nooku Framework
Joomladay Es 2009 - Nooku Framework
 
Create ReactJS Component & publish as npm package
Create ReactJS Component & publish as npm packageCreate ReactJS Component & publish as npm package
Create ReactJS Component & publish as npm package
 

Destacado

Jkadien slide share on youtube
Jkadien   slide share on youtubeJkadien   slide share on youtube
Jkadien slide share on youtubejkadien
 
ENR Global Construction Summit 2013
ENR Global Construction Summit 2013ENR Global Construction Summit 2013
ENR Global Construction Summit 2013enrevents
 
Fever coach 디지털헬스케어
Fever coach 디지털헬스케어Fever coach 디지털헬스케어
Fever coach 디지털헬스케어Jaewon Shin
 
Headaches presentation at www.eyenirvaan.com
Headaches presentation at www.eyenirvaan.comHeadaches presentation at www.eyenirvaan.com
Headaches presentation at www.eyenirvaan.comEyenirvaan
 

Destacado (6)

Jkadien slide share on youtube
Jkadien   slide share on youtubeJkadien   slide share on youtube
Jkadien slide share on youtube
 
Nbr9077
Nbr9077Nbr9077
Nbr9077
 
ENR Global Construction Summit 2013
ENR Global Construction Summit 2013ENR Global Construction Summit 2013
ENR Global Construction Summit 2013
 
Fever coach 디지털헬스케어
Fever coach 디지털헬스케어Fever coach 디지털헬스케어
Fever coach 디지털헬스케어
 
Headache
HeadacheHeadache
Headache
 
Headaches presentation at www.eyenirvaan.com
Headaches presentation at www.eyenirvaan.comHeadaches presentation at www.eyenirvaan.com
Headaches presentation at www.eyenirvaan.com
 

Similar a JS Module Server

Webpack Introduction
Webpack IntroductionWebpack Introduction
Webpack IntroductionAnjali Chawla
 
webpack introductionNotice Demystifyingf
webpack introductionNotice Demystifyingfwebpack introductionNotice Demystifyingf
webpack introductionNotice DemystifyingfMrVMNair
 
Developing for Mobile
Developing for MobileDeveloping for Mobile
Developing for MobileRemy Sharp
 
Improving build solutions dependency management with webpack
Improving build solutions  dependency management with webpackImproving build solutions  dependency management with webpack
Improving build solutions dependency management with webpackNodeXperts
 
Social Connections VI — IBM Connections Extensions and Themes Demystified
Social Connections VI — IBM Connections Extensions and Themes DemystifiedSocial Connections VI — IBM Connections Extensions and Themes Demystified
Social Connections VI — IBM Connections Extensions and Themes DemystifiedClaudio Procida
 
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...JSFestUA
 
Seven Versions of One Web Application
Seven Versions of One Web ApplicationSeven Versions of One Web Application
Seven Versions of One Web ApplicationYakov Fain
 
JSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontendJSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontendVlad Fedosov
 
Front-end build tools - Webpack
Front-end build tools - WebpackFront-end build tools - Webpack
Front-end build tools - WebpackRazvan Rosu
 
[Patel] SPFx: An ISV Insight into latest Microsoft's customization model
[Patel] SPFx: An ISV Insight into latest Microsoft's customization model[Patel] SPFx: An ISV Insight into latest Microsoft's customization model
[Patel] SPFx: An ISV Insight into latest Microsoft's customization modelEuropean Collaboration Summit
 
Modern UI Development With Node.js
Modern UI Development With Node.jsModern UI Development With Node.js
Modern UI Development With Node.jsRyan Anklam
 
Node JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppNode JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppEdureka!
 
Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)
Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)
Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)Chris O'Brien
 
Tech 2 - Introduction to the Code
Tech 2 - Introduction to the CodeTech 2 - Introduction to the Code
Tech 2 - Introduction to the CodeAidIQ
 
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTYWilliam Chong
 

Similar a JS Module Server (20)

A team 43 C
A team 43 CA team 43 C
A team 43 C
 
Webpack Introduction
Webpack IntroductionWebpack Introduction
Webpack Introduction
 
webpack introductionNotice Demystifyingf
webpack introductionNotice Demystifyingfwebpack introductionNotice Demystifyingf
webpack introductionNotice Demystifyingf
 
Developing for Mobile
Developing for MobileDeveloping for Mobile
Developing for Mobile
 
Webpack
WebpackWebpack
Webpack
 
Webpack
WebpackWebpack
Webpack
 
Improving build solutions dependency management with webpack
Improving build solutions  dependency management with webpackImproving build solutions  dependency management with webpack
Improving build solutions dependency management with webpack
 
Webpack: from 0 to 2
Webpack: from 0 to 2Webpack: from 0 to 2
Webpack: from 0 to 2
 
Social Connections VI — IBM Connections Extensions and Themes Demystified
Social Connections VI — IBM Connections Extensions and Themes DemystifiedSocial Connections VI — IBM Connections Extensions and Themes Demystified
Social Connections VI — IBM Connections Extensions and Themes Demystified
 
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
 
micro-frontends-with-vuejs
micro-frontends-with-vuejsmicro-frontends-with-vuejs
micro-frontends-with-vuejs
 
Seven Versions of One Web Application
Seven Versions of One Web ApplicationSeven Versions of One Web Application
Seven Versions of One Web Application
 
JSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontendJSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontend
 
Front-end build tools - Webpack
Front-end build tools - WebpackFront-end build tools - Webpack
Front-end build tools - Webpack
 
[Patel] SPFx: An ISV Insight into latest Microsoft's customization model
[Patel] SPFx: An ISV Insight into latest Microsoft's customization model[Patel] SPFx: An ISV Insight into latest Microsoft's customization model
[Patel] SPFx: An ISV Insight into latest Microsoft's customization model
 
Modern UI Development With Node.js
Modern UI Development With Node.jsModern UI Development With Node.js
Modern UI Development With Node.js
 
Node JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppNode JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web App
 
Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)
Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)
Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)
 
Tech 2 - Introduction to the Code
Tech 2 - Introduction to the CodeTech 2 - Introduction to the Code
Tech 2 - Introduction to the Code
 
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
 

Más de Szabolcs Szabolcsi-Tóth

Más de Szabolcs Szabolcsi-Tóth (6)

Healthy & fit wombats for the greater good
Healthy & fit wombats for the greater goodHealthy & fit wombats for the greater good
Healthy & fit wombats for the greater good
 
Cacheredirects
CacheredirectsCacheredirects
Cacheredirects
 
JavaScript - Hogyan készül
JavaScript - Hogyan készülJavaScript - Hogyan készül
JavaScript - Hogyan készül
 
Next.js & Apollo GraphQL: Using fetchMore()
Next.js & Apollo GraphQL: Using fetchMore()Next.js & Apollo GraphQL: Using fetchMore()
Next.js & Apollo GraphQL: Using fetchMore()
 
Redundant devops
Redundant devopsRedundant devops
Redundant devops
 
Cafè Terminal
Cafè TerminalCafè Terminal
Cafè Terminal
 

Último

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 

Último (20)

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 

JS Module Server

  • 1. Loading Javascript Szabolcsi-Tóth Szabolcs Senior Frontend Developer at Ustream. @_Nec nec@shell8.net
  • 2. Loading Javascript These slides are not about: detailing defer/FIF js embedding on site or putting the js after the body or in the head These slides are supposed to be about: detailing why static js loading, packaging and building leads to nowhere on the long run and a possible solution
  • 3. Inline scripting ● Quick sandboxing ● Small demos ● Learning ● Testing http://www.flickr.com/photos/pfly/399346124/
  • 4. Javascript Files ● Separate code from markup ● Serve assets from a server http://www.flickr.com/photos/seiho/2183406722/
  • 5. Code organization Webapp complexity increases Loadtime becomes an issue :( Use of functions, classes, modules Codebase grows http://www.flickr.com/photos/chiotsrun/4390949664/
  • 6. Code compilation / build Much less http requests Tools: ● concatenation ● uglify / yuicompressor http://www.flickr.com/photos/halfbisqued/2353845688/
  • 7. Code compilation / build Compile all the js that the current page might need: Several smaller files Compile all js that we need: One huge file Create js groups according to page needs http://www.flickr.com/photos/halfbisqued/2353845688/
  • 8. Code compilation / build Compile all the js that the current page might need: Several smaller files Compile all js that we need: One huge file Create js groups according to page needs What is the problem with that? http://www.flickr.com/photos/halfbisqued/2353845688/
  • 9. Take any page, coded, optimized, built, deployed
  • 10. Uh-Oh.. The Product / UX / Design division enters the room!
  • 11. The new killer feature, that saves us! Click here to close
  • 12. Code compilation / build The given feature is used on the page, or The visitor might use it on the page "the current page might need" One page gets n+1 new feature: The js compiled group for that page grows even more heavy Do we really need it onLoad? Lots of unused code, that waits for the user: overhead, slows load time. http://www.flickr.com/photos/halfbisqued/2353845688/
  • 13. Async loading! Load only the most necessary js onLoad! Then, for every feature the user wants, load the js runtime. http://www.flickr.com/photos/thenationalguard/8029811025/ ● Feature based code, not page based code ● Small lag in UX, but faster page start ● Loose module coupling, better code
  • 14. Code compilation / build Compile all the js that the current page might need: Several smaller files Compile all js that we need: One huge file Create js groups according to page needs And what is the problem with that? http://www.flickr.com/photos/halfbisqued/2353845688/
  • 15. Dependency handling The problem with predefined js groups: http://www.flickr.com/photos/wongjunhao/2761709029/ ● add js by planned use (add a feature, that can be used) ● add js by failsafe use ("this might come handy" or "make sure to have this") ● group is built at deploy
  • 16. Dependency handling The group is created for a planned usage The group contents has nothing to do with the real functioning site or app http://www.flickr.com/photos/wongjunhao/2761709029/
  • 17. Dependency handling Let the js codebase define it's own dependency Here come the modules! AMD (Asynchronous Module Definition) Designed for the web CommonJS Designed for the server (nodejs) http://www.flickr.com/photos/wongjunhao/2761709029/
  • 18. Dependency handling AMD structure define ( // optional, used in build code 'moduleName', // dependencies ['modules/Module1', 'modules/Module2'], // module definition function (module1, module2) { }); http://www.flickr.com/photos/wongjunhao/2761709029/
  • 19. Async loading + Modules Module loader a javascript utility, that: ● handles module definitions and requirements ● loads modules from a remote server require.js, curl.js, etc http://www.flickr.com/photos/redux/4298421692/
  • 20. Async loading + Modules Require.js example http://www.flickr.com/photos/redux/4298421692/ Every dependency starts a new request Lots of requests - not very good
  • 21. Async loading + Modules Need fewer requests? Introduce async packaging! http://www.flickr.com/photos/redux/4298421692/ Request and load packaged javascripts async, instead of each file. But how will the client know of the available package list?
  • 22. Async loading + Modules Possible solution: expose the built package list, and contents to the client http://www.flickr.com/photos/redux/4298421692/ Why not? In case of a large codebase, this can be an uncomfortably large amount of data. Also, exposes the whole codebase to the client.
  • 23. Async loading + Modules Another problem with pre-built packages, prepared for async load: Overlapping dependencies are inevitable http://www.flickr.com/photos/redux/4298421692/ Pack_1 Pack_2 Pack_3 Foo.js Foo.js Bar.js Bar.js Either package every common dependency, every time it's needed...
  • 24. Async loading + Modules Overlapping dependencies... Or put those commons to the page onLoad http://www.flickr.com/photos/redux/4298421692/ Pack_1 Pack_2 Pack_3 Pack_onLoad Foo.js Bar.js Codebase at onLoad starts grow fast, getting slower pageload :(
  • 25. Async loading + Modules So... http://www.flickr.com/photos/redux/4298421692/ Either we have lots of requests Or big files, with massive redundancy and duplicated code. Pack_1 Pack_2 Pack_3 Foo.js Foo.js Bar.js Bar.js
  • 26. Async loading + Modules Are we keep circling around the same issue? http://www.flickr.com/photos/redux/4298421692/
  • 27. JS Module Server Time to rethink the way of serving javascript instead of loading it as a fully static asset. Put the dependency handling to the server side. http://www.flickr.com/photos/alca_impenne/4295937972/
  • 28. JS Module Server Credit where it's due! Malte Ubl & John Hjelmstad http://www.youtube.com/watch?v=mGENRKrdoGY Two guys at Google/Gmail http://www.flickr.com/photos/alca_impenne/4295937972/
  • 29. JS Module Server Request just one module, the server finds it's dependencies, packs and serves. /js/+app/Foo.js On the client side, we keep track of what modules have been requested already. http://www.flickr.com/photos/alca_impenne/4295937972/
  • 30. JS Module Server At the next requested module, we tell the server which modules were requested already (note: not all the received, just the requested) These are "subtracted" from the request /js/+app/Bar-app/Foo.js http://www.flickr.com/photos/alca_impenne/4295937972/
  • 31. JS Module Server /js/+app/Bar-app/Foo.js The server takes the requested module dependencies, and subtracts all those, that have been served for the client already. The new package only contains code that haven't been loaded by the client. http://www.flickr.com/photos/alca_impenne/4295937972/
  • 32. JS Module Server /js/ +app/Bar - app/Foo.js No redundant modules. app/Bar class/Lorem class/Ipsum class/Sit ... app/Foo class/Lorem class/Sit class/Dolor ... app/Bar class/Ipsum ...
  • 33. JS Module Server Providing solution for: " lots of requests " Thinking in feature-oriented code, instead of the page- oriented code, these async loads can refer to only the requested feature. One request per feature. " big files, with massive redundancy and duplicated code " Only that code is packaged, that haven't been served already. http://www.flickr.com/photos/alca_impenne/4295937972/
  • 34. JS Module Server Additional gains ● full i18n support (can require groups by locale) ● cacheable urls ● sourcemap support (via uglify2) ● the full codebase is loaded by the server, it can run tasks on it, debug output, etc. (strip all console.* for example) ● could handle CSS later (with supporting preprocessors like SASS/LESS) http://www.flickr.com/photos/alca_impenne/4295937972/
  • 35. JS Module Server ● Parallel requests (add a counter-callback parameter, which determines the right parse order for the module loader, like JSONP) ● Handle browser cache properly (this one is a tricky one, but we're on the way. Changing the url is 100% sure, but If-Modified-Since would be nicer) Things to be done http://www.flickr.com/photos/alca_impenne/4295937972/
  • 36. JS Module Server Things to be done ● Put it to production (soon on Ustream) ● Open source it (soon on GitHub) http://www.flickr.com/photos/alca_impenne/4295937972/