SlideShare a Scribd company logo
Distributed JavaScript
                        Widgets w/ jQuery
                                   jQueryConf Boston 2010




Sunday, October 17, 2010
Who invited this guy?


                    • Ben Vinegar
                    • Front-end Engineer at Disqus
                    • Former team lead at FreshBooks
                    • Somewhere in there, Guestlist

Sunday, October 17, 2010
•      dis·cuss • dĭ-skŭs'

                    • Distributed commenting platform
                    • Served on over 300k sites
                    • ~200m unique visitors per month

Sunday, October 17, 2010
What’s a distributed
                            JavaScript widget?



Sunday, October 17, 2010
Sunday, October 17, 2010
Sunday, October 17, 2010
Vague definition

                    • Begins with a JavaScript snippet
                    • Lives on somebody else’s website
                    • Visible, interactive UI elements


Sunday, October 17, 2010
Let’s make one



Sunday, October 17, 2010
The pitch




Sunday, October 17, 2010
index.html




Sunday, October 17, 2010
widget.js




Sunday, October 17, 2010
widget.js cont’d




Sunday, October 17, 2010
Where’s jQuery?



Sunday, October 17, 2010
Some choices

                    • Distribute jQuery include with snippet

                    • Copy/paste into widget.js
                    • Dynamic script include from widget.js

Sunday, October 17, 2010
Dynamic include




Sunday, October 17, 2010
More problems



Sunday, October 17, 2010
jQuery conflicts

                    • What if it already exists? (Likely)
                    • Use $.noConflict
                    • Does more than let you use Dojo,
                           Mootools, Prototype ...




Sunday, October 17, 2010
Our jquery.js




Sunday, October 17, 2010
Back to our widget



Sunday, October 17, 2010
widget.js




Sunday, October 17, 2010
How to get this?




Sunday, October 17, 2010
Server-side




Sunday, October 17, 2010
Reading script QS




Sunday, October 17, 2010
Alternatively




Sunday, October 17, 2010
Another approach




Sunday, October 17, 2010
Getting the data



Sunday, October 17, 2010
Talking to the server




Sunday, October 17, 2010
Making the request




Sunday, October 17, 2010
Same-origin policy




Sunday, October 17, 2010
XDR flavours
                    • JSONP
                    • window.postMessage
                    • Server-side proxy
                    • url fragment (#)
                    • window.name
                    • CORS
Sunday, October 17, 2010
There’s a talk for that

                            “Breaking the Cross Domain Barrier”
                                 by Alex Sexton @ TXJS ’10

Sunday, October 17, 2010
JSONP




Sunday, October 17, 2010
JSONP




Sunday, October 17, 2010
postMessage




Sunday, October 17, 2010
postMessage


                    • Lets you send messages to windows/frames
                    • Oh, and receive them too


Sunday, October 17, 2010
postMessage big picture




Sunday, October 17, 2010
requestTalkData




Sunday, October 17, 2010
easyXDM

                    • Exposes a postMessage-like interface to
                           communicate with windows/frames
                    • But backwards compatible with older
                           browsers using whatever-works
                    • http://easyxdm.net

Sunday, October 17, 2010
Home stretch



Sunday, October 17, 2010
Render our data




Sunday, October 17, 2010
renderWidget




Sunday, October 17, 2010
cleanslate.css


                    • Like reset.css, but works on a container
                    • http://github.com/premasagar/cleanslate


Sunday, October 17, 2010
attachEvents




Sunday, October 17, 2010
Sunday, October 17, 2010
A quick note about
                                security


Sunday, October 17, 2010
What if ...




Sunday, October 17, 2010
Play it safe with iframes

                    • Don’t expose vulnerable actions on the
                           website host
                    • Hide them behind an iframe
                    • Restrict endpoint requests to originate
                           from iframe



Sunday, October 17, 2010
Sunday, October 17, 2010
Parting if-I-have-time
                                 wisdom


Sunday, October 17, 2010
Blocking scripts

                    • You can’t guarantee users will put your
                           snippet at the end of the page
                    • Their mistake, but your app’s reputation
                    • Difficult to change later


Sunday, October 17, 2010
Version like a pro

                    • You will inevitably have multiple versions
                    • Can you serve both at the same time, on
                           the same page?
                    • Getting people to upgrade is hard


Sunday, October 17, 2010
Thanks

                    • Ben Vinegar
                    • @bentlegen | http://benv.ca
                    • Disqus is hiring
                           http://disqus.com/jobs




Sunday, October 17, 2010

More Related Content

What's hot (8)

PDF
Nuxeo World 2013] HOW TO CONTRIBUTE TO THE COMMUNITY - LAURENT DOGUIN
Nuxeo
 
PDF
Introduction to Git
jherdman
 
PDF
RubyConf UY 2010
Brian Ford
 
PDF
Ruby off Rails
Cyril Ucron David
 
PDF
MySQL Sandbox - A toolkit for laziness
Giuseppe Maxia
 
PDF
Scareware Traversing the World via Ireland
Mark Hillick
 
PDF
Rapid Prototyping
Jeremy Baker
 
PDF
Architecting for the Enterprise
Sencha
 
Nuxeo World 2013] HOW TO CONTRIBUTE TO THE COMMUNITY - LAURENT DOGUIN
Nuxeo
 
Introduction to Git
jherdman
 
RubyConf UY 2010
Brian Ford
 
Ruby off Rails
Cyril Ucron David
 
MySQL Sandbox - A toolkit for laziness
Giuseppe Maxia
 
Scareware Traversing the World via Ireland
Mark Hillick
 
Rapid Prototyping
Jeremy Baker
 
Architecting for the Enterprise
Sencha
 

Similar to Building Distributed JavaScript Widgets with jQuery (20)

PDF
A Re-Introduction to Third-Party Scripting
benvinegar
 
PDF
Re-Introduction to Third-party Scripting
benvinegar
 
PDF
Reef - ESUG 2010
Esteban Lorenzano
 
PDF
Not Only Drupal
mcantelon
 
PDF
WordPress Front End Optimizations
Scott Taylor
 
PDF
Human APIs - expanding the mobile web or are robots coming to JavaScript?
Nikolai Onken
 
PDF
Sencha Touch beta — Amazing Mobile Web Apps with HTML5, CSS3 & JavaScript
David Kaneda
 
PDF
Mobile Development with uPortal and Infusion
colinbdclark
 
PDF
Open End To End Js Stack
Skills Matter
 
PDF
Node.js and Ruby
Michael Bleigh
 
PDF
Progressive Advancement, by way of progressive enhancement
Paul Irish
 
PDF
From where OpenVBX came from to how we open sourced it
minddog
 
PDF
Sencha Touch for the Mobile Web
Sencha
 
PDF
Do Try This At Home Ajax Bookmarking, Cross Site Scripting, And Other Web 2 ...
jward5519
 
PDF
Calloway introduction
Corey Oordt
 
PDF
Websockets - OMG! Someone broke the internet!
James Lewis
 
PDF
Developing Plugins on OpenVBX at Greater San Francisco Bay Area LAMP Group
minddog
 
KEY
Remixing Confluence With Speakeasy
nabeelahali
 
PDF
Html5/CSS3 in shanghai 2010
Zi Bin Cheah
 
PDF
Writing Your First WordPress Plugin
Mark Jaquith
 
A Re-Introduction to Third-Party Scripting
benvinegar
 
Re-Introduction to Third-party Scripting
benvinegar
 
Reef - ESUG 2010
Esteban Lorenzano
 
Not Only Drupal
mcantelon
 
WordPress Front End Optimizations
Scott Taylor
 
Human APIs - expanding the mobile web or are robots coming to JavaScript?
Nikolai Onken
 
Sencha Touch beta — Amazing Mobile Web Apps with HTML5, CSS3 & JavaScript
David Kaneda
 
Mobile Development with uPortal and Infusion
colinbdclark
 
Open End To End Js Stack
Skills Matter
 
Node.js and Ruby
Michael Bleigh
 
Progressive Advancement, by way of progressive enhancement
Paul Irish
 
From where OpenVBX came from to how we open sourced it
minddog
 
Sencha Touch for the Mobile Web
Sencha
 
Do Try This At Home Ajax Bookmarking, Cross Site Scripting, And Other Web 2 ...
jward5519
 
Calloway introduction
Corey Oordt
 
Websockets - OMG! Someone broke the internet!
James Lewis
 
Developing Plugins on OpenVBX at Greater San Francisco Bay Area LAMP Group
minddog
 
Remixing Confluence With Speakeasy
nabeelahali
 
Html5/CSS3 in shanghai 2010
Zi Bin Cheah
 
Writing Your First WordPress Plugin
Mark Jaquith
 
Ad

Recently uploaded (20)

PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Biography of Daniel Podor.pdf
Daniel Podor
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
Ad

Building Distributed JavaScript Widgets with jQuery