SlideShare a Scribd company logo
Building a JavaScript
Module Framework
       at Gilt


       Eric Shepherd
         @arkitrave
Whois?

‣   background
    ‣   music | architecture |
        web design | front end engineering
‣   companies
    ‣   fisher-price | condé nast | gilt groupe
Thank You!
‣   Nicholas Zakas
    ‣   scalable javascript application
        architecture presentation
‣   jQuery Conference 2010
    ‣   presentations on pubsub, templating,
        yepnope, and js architecture
Why?
Why?


‣   code organization
    ‣   small files + objects, each with a
        defined role
Why?

‣   code organization
‣   reduce points of dependency
    ‣   modules communicate through only
        one channel
Why?

‣   code organization
‣   reduce points of dependency
‣   unobtrusiveness for third-parties
    ‣   other sites can include your code
        without fear
Why?
‣   code organization
‣   reduce points of dependency
‣   unobtrusiveness for third-parties
‣   adaptability + extensibility
    ‣   any piece of the application can be
        switched out without affecting the
        rest of the application
Demands
Demands


‣   allows multiple unique module
    instances
Demands

‣   allows multiple unique module
    instances
‣   does not allow modules to talk to
    each other
    ‣   freedom in clear boundaries
Demands
‣   allows multiple unique module
    instances
‣   does not allow modules to talk to
    each other
‣   tightly restricts dom access (with a
    few exceptions)
    ‣   the page doesn’t need to worry
        about being messed with
Demands
‣   allows multiple unique module
    instances
‣   does not allow modules to talk to
    each other
‣   tightly restricts dom access (with a
    few exceptions)
‣   touches as little global code as
    possible
    ‣   ideally, only one global var
Components
Components
‣   Gilt.App
    ‣   there is only one
    ‣   manages all modules, provides one
        sandbox to each module
    ‣   public api is register(), start(), stop(),
        startAll(), stopAll(), view.register()
Components

‣   Gilt.App
‣   Gilt.Sandbox
    ‣   instantiable, one instance per module
    ‣   provides pubsub, state management,
        dom interaction, services, views
Components
‣   Gilt.App
‣   Gilt.Sandbox
‣   module itself
    ‣   implements a simple create() and
        destroy() interface
    ‣   it’s an overprotected child, with a
        limited view of the world
Components

‣   Gilt.App
‣   Gilt.Sandbox
‣   module itself
‣   …along with core code and helpers
Architecture
Flow
‣   a module is a function, passed to
    App.register() as a creator
‣   on App.start(), a new Sandbox()
    instance is passed to that creator,
    which returns public create and
    destroy methods, and…
‣   the new module instance’s create() is
    called
Architecture
Gilt.App
Gilt.App
Architecture
Gilt.Sandbox
Gilt.Sandbox
Architecture
Module
Module
Module View (opt.)
Module View (opt.)
Architecture
The Hoff Helpers
‣   jQuery
‣   underscore.js
‣   handlebars.js
‣   yepnope.js
‣   &c…but modules can’t know
    anything about these (jQuery as a
    partial exception due to its plugin
    architecture)
Architecture
Wiring It Up

‣   on your own site
    ‣   page controller
‣   on a third-party site
    ‣   bootstrap as js loader and controller
WTF
A Better Bootstrap
‣   don’t be a jerk – think of the children
‣   protect the global scope – you’re in
    someone else’s house!
‣   make it easy to inline or inject the
    script dynamically
‣   keep the payload light – it’s like
    spending someone else’s money
A Better Bootstrap
…Which Returns…
Server-Generated
     Closure
Yep. Nope.
Watch Out For…
Watch Out For…


‣   make sure your bootstrap is RESTful
Watch Out For…
‣   make sure your bootstrap is RESTful
‣   css
    ‣   conflicts are a bitch
    ‣   and you can’t use id selectors
    ‣   !important is your only hope
    ‣   jquery.important can help, but it’s the
        roach motel, and animations are out
Watch Out For…
‣   make sure your bootstrap is RESTful
‣   css
‣   jQuery
    ‣   plugin convention requires a globally-
        accessible jQuery object
    ‣   so noConflict(true) will work only if
        you don’t need plugins
    ‣   use sandbox.getContainer().find()
Watch Out For…

‣   make sure your bootstrap is RESTful
‣   css
‣   jQuery
‣   cross-domain issues
    ‣   make sure your feeds are jsonp
Watch Out For…
‣   make sure your bootstrap is RESTful
‣   css
‣   jQuery
‣   cross-domain issues
‣   assumptions of shared code
    ‣   included code can later introduce
        dependencies unavailable on a third-
        party site, hard to test
You Can Do Anything

‣   anything at all
‣   the only limit is yourself
‣   …yes…
Questions?

‣   Eric Shepherd
‣   eric@arkitrave.com
‣   @arkitrave

More Related Content

PPTX
Scalable JavaScript Application Architecture 2012
Nicholas Zakas
 
PDF
Building Large Scale Javascript Application
Anis Ahmad
 
PDF
Javascript Design Patterns
Lilia Sfaxi
 
PDF
jQquerysummit - Large-scale JavaScript Application Architecture
Jiby John
 
PDF
Large-Scale JavaScript Development
Addy Osmani
 
PPT
Struts2 course chapter 1: Evolution of Web Applications
JavaEE Trainers
 
PDF
Client-side JavaScript
Lilia Sfaxi
 
PDF
Design Patterns in iOS
Yi-Shou Chen
 
Scalable JavaScript Application Architecture 2012
Nicholas Zakas
 
Building Large Scale Javascript Application
Anis Ahmad
 
Javascript Design Patterns
Lilia Sfaxi
 
jQquerysummit - Large-scale JavaScript Application Architecture
Jiby John
 
Large-Scale JavaScript Development
Addy Osmani
 
Struts2 course chapter 1: Evolution of Web Applications
JavaEE Trainers
 
Client-side JavaScript
Lilia Sfaxi
 
Design Patterns in iOS
Yi-Shou Chen
 

What's hot (14)

PPTX
Built to last javascript for enterprise
Marjan Nikolovski
 
KEY
iOS Design Patterns
Andreas Blick
 
PDF
JavaScript Modules Done Right
Mariusz Nowak
 
PPT
Gnizr Architecture (for developers)
hchen1
 
PDF
Design Patterns
Ahmad Hussein
 
PPTX
Design Pattern - Singleton Pattern
Mudasir Qazi
 
PDF
Rp 6 session 2 naresh bhatia
sapientindia
 
PPTX
Singleton Design Pattern - Creation Pattern
Seerat Malik
 
PPTX
The Singleton Pattern Presentation
JAINIK PATEL
 
PDF
Tips & Tricks Android
intive
 
PPT
Jump Start To Ooad And Design Patterns
Lalit Kale
 
ODP
Object Oriented Prograring(OOP) java
GaddafiAdamu1
 
PDF
Best interview questions
Thesis Scientist Private Limited
 
PPTX
Singleton Pattern (Sole Object with Global Access)
Sameer Rathoud
 
Built to last javascript for enterprise
Marjan Nikolovski
 
iOS Design Patterns
Andreas Blick
 
JavaScript Modules Done Right
Mariusz Nowak
 
Gnizr Architecture (for developers)
hchen1
 
Design Patterns
Ahmad Hussein
 
Design Pattern - Singleton Pattern
Mudasir Qazi
 
Rp 6 session 2 naresh bhatia
sapientindia
 
Singleton Design Pattern - Creation Pattern
Seerat Malik
 
The Singleton Pattern Presentation
JAINIK PATEL
 
Tips & Tricks Android
intive
 
Jump Start To Ooad And Design Patterns
Lalit Kale
 
Object Oriented Prograring(OOP) java
GaddafiAdamu1
 
Best interview questions
Thesis Scientist Private Limited
 
Singleton Pattern (Sole Object with Global Access)
Sameer Rathoud
 
Ad

Viewers also liked (7)

PPTX
Browser Wars Episode 1: The Phantom Menace
Nicholas Zakas
 
PDF
Scalable JavaScript Application Architecture
Nicholas Zakas
 
PPT
Wakanday JS201 Best Practices
Juergen Fesslmeier
 
PDF
Getting started with YUI3 and AlloyUI
Zeno Rocha
 
PDF
Our Best Practices Are Killing Us
Nicole Sullivan
 
PPTX
Maintainable JavaScript 2012
Nicholas Zakas
 
PDF
Guided Reading: Making the Most of It
Jennifer Jones
 
Browser Wars Episode 1: The Phantom Menace
Nicholas Zakas
 
Scalable JavaScript Application Architecture
Nicholas Zakas
 
Wakanday JS201 Best Practices
Juergen Fesslmeier
 
Getting started with YUI3 and AlloyUI
Zeno Rocha
 
Our Best Practices Are Killing Us
Nicole Sullivan
 
Maintainable JavaScript 2012
Nicholas Zakas
 
Guided Reading: Making the Most of It
Jennifer Jones
 
Ad

Similar to Building a JavaScript Module Framework at Gilt (20)

PDF
iOS Indie Developer Toolkit - CocoaHeads 3city
Michał Zygar
 
PDF
2013-03-07 indie developer toolkit
CocoaHeads Tricity
 
PDF
Mobile for PHP developers
Ivo Jansch
 
KEY
Angels versus demons: balancing shiny and inclusive
Chris Mills
 
PDF
Mobile Web & HTML5 Performance Optimization
Maximiliano Firtman
 
PDF
Continuous Deployment - Developers Conference Hamburg #dchh
Dirk Hoerig
 
PDF
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
mfrancis
 
PDF
GWT widget development
pgt technology scouting GmbH
 
PDF
A Period of Transition
Jens Grochtdreis
 
PDF
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Fabian Jakobs
 
KEY
Pure Sign Breakfast Presentations - Drupal FieldAPI
Pure Sign
 
PDF
Real solutions, no tricks
Jens Grochtdreis
 
PPTX
Build Automation in Android
Angelo Rüggeberg
 
PDF
Guides To Analyzing WebKit Performance
National Cheng Kung University
 
PPTX
Building a µservice with Kotlin, Micronaut & GCP
Robert MacLean
 
PDF
Dev objective2015 lets git together
ColdFusionConference
 
PDF
Lets git together
devObjective
 
PDF
Real World Progressive Web Apps (Building Flipkart Lite)
Abhinav Rastogi
 
PDF
Quo vadis, JavaScript? Devday.pl keynote
Christian Heilmann
 
PPTX
OpenDaylight Developer Experience 2.0
Michael Vorburger
 
iOS Indie Developer Toolkit - CocoaHeads 3city
Michał Zygar
 
2013-03-07 indie developer toolkit
CocoaHeads Tricity
 
Mobile for PHP developers
Ivo Jansch
 
Angels versus demons: balancing shiny and inclusive
Chris Mills
 
Mobile Web & HTML5 Performance Optimization
Maximiliano Firtman
 
Continuous Deployment - Developers Conference Hamburg #dchh
Dirk Hoerig
 
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
mfrancis
 
GWT widget development
pgt technology scouting GmbH
 
A Period of Transition
Jens Grochtdreis
 
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Fabian Jakobs
 
Pure Sign Breakfast Presentations - Drupal FieldAPI
Pure Sign
 
Real solutions, no tricks
Jens Grochtdreis
 
Build Automation in Android
Angelo Rüggeberg
 
Guides To Analyzing WebKit Performance
National Cheng Kung University
 
Building a µservice with Kotlin, Micronaut & GCP
Robert MacLean
 
Dev objective2015 lets git together
ColdFusionConference
 
Lets git together
devObjective
 
Real World Progressive Web Apps (Building Flipkart Lite)
Abhinav Rastogi
 
Quo vadis, JavaScript? Devday.pl keynote
Christian Heilmann
 
OpenDaylight Developer Experience 2.0
Michael Vorburger
 

Recently uploaded (20)

PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PPTX
Coupa-Overview _Assumptions presentation
annapureddyn
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PPTX
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PPT
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Coupa-Overview _Assumptions presentation
annapureddyn
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 

Building a JavaScript Module Framework at Gilt

  • 1. Building a JavaScript Module Framework at Gilt Eric Shepherd @arkitrave
  • 2. Whois? ‣ background ‣ music | architecture | web design | front end engineering ‣ companies ‣ fisher-price | condé nast | gilt groupe
  • 3. Thank You! ‣ Nicholas Zakas ‣ scalable javascript application architecture presentation ‣ jQuery Conference 2010 ‣ presentations on pubsub, templating, yepnope, and js architecture
  • 5. Why? ‣ code organization ‣ small files + objects, each with a defined role
  • 6. Why? ‣ code organization ‣ reduce points of dependency ‣ modules communicate through only one channel
  • 7. Why? ‣ code organization ‣ reduce points of dependency ‣ unobtrusiveness for third-parties ‣ other sites can include your code without fear
  • 8. Why? ‣ code organization ‣ reduce points of dependency ‣ unobtrusiveness for third-parties ‣ adaptability + extensibility ‣ any piece of the application can be switched out without affecting the rest of the application
  • 10. Demands ‣ allows multiple unique module instances
  • 11. Demands ‣ allows multiple unique module instances ‣ does not allow modules to talk to each other ‣ freedom in clear boundaries
  • 12. Demands ‣ allows multiple unique module instances ‣ does not allow modules to talk to each other ‣ tightly restricts dom access (with a few exceptions) ‣ the page doesn’t need to worry about being messed with
  • 13. Demands ‣ allows multiple unique module instances ‣ does not allow modules to talk to each other ‣ tightly restricts dom access (with a few exceptions) ‣ touches as little global code as possible ‣ ideally, only one global var
  • 15. Components ‣ Gilt.App ‣ there is only one ‣ manages all modules, provides one sandbox to each module ‣ public api is register(), start(), stop(), startAll(), stopAll(), view.register()
  • 16. Components ‣ Gilt.App ‣ Gilt.Sandbox ‣ instantiable, one instance per module ‣ provides pubsub, state management, dom interaction, services, views
  • 17. Components ‣ Gilt.App ‣ Gilt.Sandbox ‣ module itself ‣ implements a simple create() and destroy() interface ‣ it’s an overprotected child, with a limited view of the world
  • 18. Components ‣ Gilt.App ‣ Gilt.Sandbox ‣ module itself ‣ …along with core code and helpers
  • 20. Flow ‣ a module is a function, passed to App.register() as a creator ‣ on App.start(), a new Sandbox() instance is passed to that creator, which returns public create and destroy methods, and… ‣ the new module instance’s create() is called
  • 33. The Hoff Helpers ‣ jQuery ‣ underscore.js ‣ handlebars.js ‣ yepnope.js ‣ &c…but modules can’t know anything about these (jQuery as a partial exception due to its plugin architecture)
  • 35. Wiring It Up ‣ on your own site ‣ page controller ‣ on a third-party site ‣ bootstrap as js loader and controller
  • 36. WTF
  • 37. A Better Bootstrap ‣ don’t be a jerk – think of the children ‣ protect the global scope – you’re in someone else’s house! ‣ make it easy to inline or inject the script dynamically ‣ keep the payload light – it’s like spending someone else’s money
  • 40. Server-Generated Closure
  • 43. Watch Out For… ‣ make sure your bootstrap is RESTful
  • 44. Watch Out For… ‣ make sure your bootstrap is RESTful ‣ css ‣ conflicts are a bitch ‣ and you can’t use id selectors ‣ !important is your only hope ‣ jquery.important can help, but it’s the roach motel, and animations are out
  • 45. Watch Out For… ‣ make sure your bootstrap is RESTful ‣ css ‣ jQuery ‣ plugin convention requires a globally- accessible jQuery object ‣ so noConflict(true) will work only if you don’t need plugins ‣ use sandbox.getContainer().find()
  • 46. Watch Out For… ‣ make sure your bootstrap is RESTful ‣ css ‣ jQuery ‣ cross-domain issues ‣ make sure your feeds are jsonp
  • 47. Watch Out For… ‣ make sure your bootstrap is RESTful ‣ css ‣ jQuery ‣ cross-domain issues ‣ assumptions of shared code ‣ included code can later introduce dependencies unavailable on a third- party site, hard to test
  • 48. You Can Do Anything ‣ anything at all ‣ the only limit is yourself ‣ …yes…
  • 49. Questions? ‣ Eric Shepherd ‣ [email protected] ‣ @arkitrave