SlideShare uma empresa Scribd logo
1 de 82
Baixar para ler offline
THE MYSTERIES OF
  JAVASCRIPT-FU
 Dan Webb (dan@danwebb.net)
About Me
    JavaScript hacker for
❖
    6 years
    Ruby/Rails for 2 years
❖

    Author of Low Pro,
❖
    DOM Builder, Sumo
    and other stuff
    Prototype Core Team
❖

    http://danwebb.net
❖
A peasant’s language
Web 2.0 has forced
‘real’ programmers to
        master it
JavaScript-Fu is not easy
       to master
The web is awash with
 bad examples and
  worse resources
Developers forced into
refuge behind libraries
    and frameworks
THE ANCIENT MANUALS
      OF JAVASCRIPT-FU
    The Tao Of The Event Handler!
❖

    5 Methods Of DOM Fist!
❖

    Lightning Script Style!
❖

    The 36 Chambers Of Shaolin!
❖
TRANSLATED...

    Working with events
❖

    Working with DOM elements
❖

    Optimisation
❖

    Testing and debugging
❖
THE TAO OF THE
EVENT HANDLER
The essence of browser
 scripting is defining
      behaviour
Big differences in both
browser implementation
      and opinion
The main battle has
always been in one
      area...
INLINE VS SCRIPTED
INLINE EVENT HANDLERS
INLINE EVENT HANDLERS




Applied as soon as the browser
loads the HTML
INLINE EVENT HANDLERS




But what happens when there
is more than one....
Bad JavaScript-fu
SCRIPT-BASED
       EVENT HANDLERS
Attached after element
      has loaded
Very DRY
Separate JavaScript out
in a similar way to CSS
Large numbers of event
handlers choke browsers
WHICH WAY?
    Use script-based event handling by
❖
    default
    If the page is large and this method
❖
    results in unresponsiveness try event
    delegation
    If all else fails go for inline event
❖
    handling
EVENT BUBBLING

 <body>     handler


 <div>

 <p>

 <a>         click
EVENT DELEGATION
BETTER INLINE HANDLERS
BETTER INLINE HANDLERS
5 METHODS OF
  DOM FIST
There are 5 methods for
    updating HTML
3 official methods
       (W3C)
$('kungfu').appendChild(node);
$('kungfu').insertBefore(node, child);
$('kungfu').replaceChild(node, child);
1 non-standard method
(you guessed it, from IE)
DOM VS innerHTML
DOM METHODS
Insert elements with
      precision
But you need to create
   the nodes first...
ARGH!
LOWPRO’S DOM BUILDER
INNERHTML
Can shift large amount
  of HTML quickly...
...but you don't get
    much control
Incredibly simple
 to use with Ajax
WHICH WAY?

    No clear winner
❖

    DOM is good for more surgical
❖
    manipulation
    innerHTML is good for replacing large
❖
    amounts of content or simple jobs
and the final method...
THE BASTARD SON
LIGHTNING
SCRIPT STYLE
~134KB
5 HTTP
requests
Takes time to download
  and evaluate script
The less JavaScript
    the better
Browsers normally only
try to load 2 resources
      concurrently
Combine .js files
Use GZIP compression
not JS based minification
Make sure everything
    is cachable
FASTER LOOPS
FASTER LOOPS
BE CAREFUL WITH
            SELECTORS
THE 36 CHAMBERS
   OF SHAOLIN
You're going to need
    a few tools...
Buy a Mac
Parallels Workstation

    PARALLELS
   WORKSTATION
Get Firebug
What about the other
    browsers?
And then there's
   testing...
SELENIUM

    Written by ThoughtWorks
❖

    Implemented in HTML/CSS
❖

    Test cases define a series of user
❖
    actions (using HTML)
    Assertions check the correct results
❖
LEARNING MORE
LEARNING MORE
    Dan Webb: http://www.danwebb.net
❖

    Low Pro: http://www.danwebb.net/lowpro
❖

    Parallels: http://parallels.com
❖

    Firebug: http://getfirebug.com
❖

    Selenium: http://www.openqa.org/
❖
    selenium/
QUESTIONS?

Mais conteúdo relacionado

Mais procurados

Automated Web App Performance Testing Using WebDriver
Automated Web App Performance Testing Using WebDriverAutomated Web App Performance Testing Using WebDriver
Automated Web App Performance Testing Using WebDriver
seleniumconf
 
Andrew Mykhaliuk - Sorry, I need to make a build for frontend
Andrew Mykhaliuk - Sorry, I need to make a build for frontendAndrew Mykhaliuk - Sorry, I need to make a build for frontend
Andrew Mykhaliuk - Sorry, I need to make a build for frontend
OdessaJS Conf
 
Web performance testing with web driver
Web performance testing with web driverWeb performance testing with web driver
Web performance testing with web driver
Michael Klepikov
 
Integrating Node.js with PHP
Integrating Node.js with PHPIntegrating Node.js with PHP
Integrating Node.js with PHP
Lee Boynton
 
Speeding up Page Load Times by Using Starling
Speeding up Page Load Times by Using StarlingSpeeding up Page Load Times by Using Starling
Speeding up Page Load Times by Using Starling
Erik Osterman
 

Mais procurados (19)

Madison PHP 2015 - DevOps For Small Teams
Madison PHP 2015 - DevOps For Small TeamsMadison PHP 2015 - DevOps For Small Teams
Madison PHP 2015 - DevOps For Small Teams
 
Testing Storm components with Groovy and Spock
Testing Storm components with Groovy and SpockTesting Storm components with Groovy and Spock
Testing Storm components with Groovy and Spock
 
CI/CD doesn’t necessarily mean Jenkins - Omer Hamerman - DevOpsDays Tel Aviv ...
CI/CD doesn’t necessarily mean Jenkins - Omer Hamerman - DevOpsDays Tel Aviv ...CI/CD doesn’t necessarily mean Jenkins - Omer Hamerman - DevOpsDays Tel Aviv ...
CI/CD doesn’t necessarily mean Jenkins - Omer Hamerman - DevOpsDays Tel Aviv ...
 
ClojureScript: I can't believe this is JavaScript
ClojureScript: I can't believe this is JavaScriptClojureScript: I can't believe this is JavaScript
ClojureScript: I can't believe this is JavaScript
 
Brief Intro to Phoenix - Elixir Meetup at BukaLapak
Brief Intro to Phoenix - Elixir Meetup at BukaLapakBrief Intro to Phoenix - Elixir Meetup at BukaLapak
Brief Intro to Phoenix - Elixir Meetup at BukaLapak
 
Add a backend and deploy!
Add a backend and deploy!Add a backend and deploy!
Add a backend and deploy!
 
Automated Web App Performance Testing Using WebDriver
Automated Web App Performance Testing Using WebDriverAutomated Web App Performance Testing Using WebDriver
Automated Web App Performance Testing Using WebDriver
 
Automated Testing with Google Chrome - WebDriver- ChromeDriver
Automated Testing with Google Chrome - WebDriver- ChromeDriverAutomated Testing with Google Chrome - WebDriver- ChromeDriver
Automated Testing with Google Chrome - WebDriver- ChromeDriver
 
Andrew Mykhaliuk - Sorry, I need to make a build for frontend
Andrew Mykhaliuk - Sorry, I need to make a build for frontendAndrew Mykhaliuk - Sorry, I need to make a build for frontend
Andrew Mykhaliuk - Sorry, I need to make a build for frontend
 
I Promise You
I Promise YouI Promise You
I Promise You
 
Web performance testing with web driver
Web performance testing with web driverWeb performance testing with web driver
Web performance testing with web driver
 
Tutorial sederhana netbeans & xampp
Tutorial sederhana netbeans & xamppTutorial sederhana netbeans & xampp
Tutorial sederhana netbeans & xampp
 
Integrating Node.js with PHP
Integrating Node.js with PHPIntegrating Node.js with PHP
Integrating Node.js with PHP
 
Overcoming Command Line Allergies
Overcoming Command Line AllergiesOvercoming Command Line Allergies
Overcoming Command Line Allergies
 
PHP and node.js Together
PHP and node.js TogetherPHP and node.js Together
PHP and node.js Together
 
Nodejs vs php_apache
Nodejs vs php_apacheNodejs vs php_apache
Nodejs vs php_apache
 
Untangling7
Untangling7Untangling7
Untangling7
 
Speeding up Page Load Times by Using Starling
Speeding up Page Load Times by Using StarlingSpeeding up Page Load Times by Using Starling
Speeding up Page Load Times by Using Starling
 
Queueing at the Checkout
Queueing at the CheckoutQueueing at the Checkout
Queueing at the Checkout
 

Semelhante a The Mysteries Of JavaScript-Fu (@media SF Edition)

Flu3nt highlights
Flu3nt highlightsFlu3nt highlights
Flu3nt highlights
dswork
 
Building with JavaScript - write less by using the right tools
Building with JavaScript -  write less by using the right toolsBuilding with JavaScript -  write less by using the right tools
Building with JavaScript - write less by using the right tools
Christian Heilmann
 
In Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps
In Pursuit of the Holy Grail: Building Isomorphic JavaScript AppsIn Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps
In Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps
Spike Brehm
 
Your java script library
Your java script libraryYour java script library
Your java script library
jasfog
 

Semelhante a The Mysteries Of JavaScript-Fu (@media SF Edition) (20)

The Mysteries Of JavaScript-Fu (RailsConf Ediition)
The Mysteries Of JavaScript-Fu (RailsConf Ediition)The Mysteries Of JavaScript-Fu (RailsConf Ediition)
The Mysteries Of JavaScript-Fu (RailsConf Ediition)
 
All of Javascript
All of JavascriptAll of Javascript
All of Javascript
 
Fast Cordova applications
Fast Cordova applicationsFast Cordova applications
Fast Cordova applications
 
A rough guide to JavaScript Performance
A rough guide to JavaScript PerformanceA rough guide to JavaScript Performance
A rough guide to JavaScript Performance
 
Killing the Angle Bracket
Killing the Angle BracketKilling the Angle Bracket
Killing the Angle Bracket
 
Agile JavaScript Testing
Agile JavaScript TestingAgile JavaScript Testing
Agile JavaScript Testing
 
Drupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp NorthDrupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp North
 
Flu3nt highlights
Flu3nt highlightsFlu3nt highlights
Flu3nt highlights
 
2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire
 
Speeding up mobile web apps
Speeding up mobile web appsSpeeding up mobile web apps
Speeding up mobile web apps
 
ZendCon 2015 - DevOps for Small Teams
ZendCon 2015 - DevOps for Small TeamsZendCon 2015 - DevOps for Small Teams
ZendCon 2015 - DevOps for Small Teams
 
Quo vadis, JavaScript? Devday.pl keynote
Quo vadis, JavaScript? Devday.pl keynoteQuo vadis, JavaScript? Devday.pl keynote
Quo vadis, JavaScript? Devday.pl keynote
 
Building with JavaScript - write less by using the right tools
Building with JavaScript -  write less by using the right toolsBuilding with JavaScript -  write less by using the right tools
Building with JavaScript - write less by using the right tools
 
Performance Tuning Web Apps - The Need For Speed
Performance Tuning Web Apps - The Need For SpeedPerformance Tuning Web Apps - The Need For Speed
Performance Tuning Web Apps - The Need For Speed
 
DevOps For Small Teams
DevOps For Small TeamsDevOps For Small Teams
DevOps For Small Teams
 
In Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps
In Pursuit of the Holy Grail: Building Isomorphic JavaScript AppsIn Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps
In Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps
 
Fast mobile web apps
Fast mobile web appsFast mobile web apps
Fast mobile web apps
 
Web Optimisation
Web OptimisationWeb Optimisation
Web Optimisation
 
Your java script library
Your java script libraryYour java script library
Your java script library
 
Midwest PHP 2017 DevOps For Small team
Midwest PHP 2017 DevOps For Small teamMidwest PHP 2017 DevOps For Small team
Midwest PHP 2017 DevOps For Small team
 

Mais de danwrong (7)

Building Non-shit APIs with JavaScript
Building Non-shit APIs with JavaScriptBuilding Non-shit APIs with JavaScript
Building Non-shit APIs with JavaScript
 
Loadrunner
LoadrunnerLoadrunner
Loadrunner
 
Bringing the Same-Origin Policy to its Knees
Bringing the Same-Origin Policy to its KneesBringing the Same-Origin Policy to its Knees
Bringing the Same-Origin Policy to its Knees
 
Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)
 
8 Minutes On Rack
8 Minutes On Rack8 Minutes On Rack
8 Minutes On Rack
 
Taming The Beast
Taming The BeastTaming The Beast
Taming The Beast
 
Metaprogramming JavaScript
Metaprogramming  JavaScriptMetaprogramming  JavaScript
Metaprogramming JavaScript
 

Último

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

The Mysteries Of JavaScript-Fu (@media SF Edition)