SlideShare a Scribd company logo
1 of 55
Download to read offline
JAVASCRIPT
                              SECRETS
                Cleaner Code/ Faster Apps



Wednesday, March 30, 2011
About me
• CTO, Modus                  Create.

     • RIA         UI/UX design

     • High-end              consulting

     • Training             / workshops

     • Architectural            guidance

     • Application             architecture

     • Specialize            in Sencha technologies.

Wednesday, March 30, 2011
Wednesday, March 30, 2011
Wednesday, March 30, 2011
Wednesday, March 30, 2011
My books




Wednesday, March 30, 2011
AGENDA
    • Discuss               some of the secrets behind JavaScript




Wednesday, March 30, 2011
1995-2005
  • Advance                  use of JavaScript was limited until ~ 2005
       • Field          validation
       • Mouse               cursor trails
       • Right              click preventers
       • Popup               storms
  • Lots           of books written
       • Many               taught bad practices



Wednesday, March 30, 2011
Today?
   • JavaScript               frameworks in use more
        • Do         more, quicker!
   • Way            better debug tools
        • Firebug

        • Webkit              inspector
        • IE8        JS debug console (IE9 is a little better)
   • HTML5                  is gaining popularity
        • Flash             is (somewhat) threatened

Wednesday, March 30, 2011
It’s a JavaScript world!




Wednesday, March 30, 2011
Arithmetic Operators




Wednesday, March 30, 2011
Arithmetic
    • Arithmetic            operators

    •+       (add/concatenate)

    •-     (subtract)

    •*      (multiplication)

    •/     (division)

    •%       (modulus/remainder)


Wednesday, March 30, 2011
Arithmetic




Wednesday, March 30, 2011
Remember
    • The         + operator has a dual purpose

        • Addition          and concatenation




Wednesday, March 30, 2011
Operator coercion
    • For        -, *, / operators,

        • JavaScript        will try to convert strings into numbers.




Wednesday, March 30, 2011
•When       at all possible, try to perform
       math using numbers instead of
       strings.
    •This   will help reduce the chance of
       errors.


Wednesday, March 30, 2011
Comparison Operators




Wednesday, March 30, 2011
Comparison operators with
                          if/then

    • Most           of us use if and then to control logic branches.

    • There            is a hidden danger with == and !=

        • Sometimes   the result of an expression test can lead to
            unexpected code behavior



Wednesday, March 30, 2011
Take the following....




Wednesday, March 30, 2011
Meet “Falsy” and “Truthy”

    • Because               JavaScript tries to coerce values, expressions using

        •     == and !=

    • Expressions              are boiled down to “Falsy” and “Truthy”

        • There   should be no room for “Falsy” and “Truthy” in
            your code.


Wednesday, March 30, 2011
Seriously?




Wednesday, March 30, 2011
Takeaway:

                              == and !=
                              are EVIL
                            Do not use them!

Wednesday, March 30, 2011
Instead...

    • Use         === and !==

        • They              are not evil :)

    • Get         expected results every time

    • both          === and !== test for value and data type

        • No          coercion takes place


Wednesday, March 30, 2011
Fight the evil.




                            All are false!
Wednesday, March 30, 2011
Hoisting




Wednesday, March 30, 2011
Hoisting

    •A  mechanism for setting and creating things in a function
       when that function is executed.

        • When     a function is executed, two passes are actually made
            on the function by the JavaScript interpreter.

        • It  can lead to much pain when dealing with function
            statements.


Wednesday, March 30, 2011
How a function really is
              interpreted at execution time




Wednesday, March 30, 2011
How a function really is
              interpreted at execution time




Wednesday, March 30, 2011
Interpretation case 2




Wednesday, March 30, 2011
More on hoisting

    • Due          to hoisting,

        • function          expressions

             • have  their reference name created first and are
                 assigned at execution time.

        • function          statements

             • have  their reference name created and are assigned
                 before execution time

Wednesday, March 30, 2011
Function statement vs. expression




Wednesday, March 30, 2011
Function statement hoisting




Wednesday, March 30, 2011
Function statement hoisting




Wednesday, March 30, 2011
This should be impossible




Wednesday, March 30, 2011
Know hoisting....
    • According  to the hoisting rules, the second jump function
       should have been created

        • Firefox            actually honors the conditional statement - what?!

    • Some             browsers follow these rules and some don’t

    • This is because the language definition doesn’t really tell you
       what it’s supposed to do, so there are different
       implementations.

    • Coding                this way can lead to unpredictable behavior of your

Wednesday, March 30, 2011
Avoid function statements!




Wednesday, March 30, 2011
JS optimizations




Wednesday, March 30, 2011
Asynchronous script tags


    • For        HTML5 enabled browsers

        • Set        async=‘async’ in your script tags.
        •   <script type=‘text/javascript’ src=’/myfile.js’ async=‘async’></script>

        • Will          allow JavaScript files to be non-blocking



Wednesday, March 30, 2011
Deferred execution

    • Set        defer=‘defer’ in your script tags.
        •   <script type=‘text/javascript’ src=’/myfile.js’ defer=‘defer’></script>

    • Will allow JavaScript code in those files to execute after the
       page has loaded.

    • Does            not work in all browsers :(


Wednesday, March 30, 2011
Minification




Wednesday, March 30, 2011
Facts about minification

    • Reduce                file size sent to the browser

    • Increase              interpretation speed of JS files by the browser

    • Some Tools:

        • Yui-Compressor

        • Google             Closure

        • Packer

Wednesday, March 30, 2011
A simple JS File




    • 183         Bytes




Wednesday, March 30, 2011
Minified



    • 103         Bytes

    • 44%          savings




Wednesday, March 30, 2011
A better JS file




    • 184         Bytes


                            Why is it better!?!?
Wednesday, March 30, 2011
‘Better code’ === ‘more savings’



    • 95       Bytes

    • 49%          Savings




Wednesday, March 30, 2011
Loops




Wednesday, March 30, 2011
Loops



      Minifier can't
      claim space


                                     Namespace
                                    lookups costly




Wednesday, March 30, 2011
Faster loops

                                   Minifier friendly




                  No initializer                      Faster Lookup




Wednesday, March 30, 2011
Better reference usage




Wednesday, March 30, 2011
Less than optimal lookups




Wednesday, March 30, 2011
Less than optimal lookups




Wednesday, March 30, 2011
Optimal lookups




Wednesday, March 30, 2011
Recap

    •+   operators will concatenate strings, while -, *, / will coerce
       values

    • Avoid “Truthy” and “Falsy” by      using === and !==

    • Use         async and defer enabled Script tags when possible.

    • Use         function expressions


Wednesday, March 30, 2011
Recap


    • Minify           your code when possible

        • Develop “Minifier-friendly” code

    • Create                optimized loops

    • Reduce                namespace lookups by using local references



Wednesday, March 30, 2011
Thanks!!!
                                Questions?

                                    Twitter: @_jdg
                              Mobile: 301-785-3030
                              Web: moduscreate.com
                            Email: jay@moduscreate.com

Wednesday, March 30, 2011

More Related Content

Viewers also liked

5 new rules for product development
5 new rules for product development5 new rules for product development
5 new rules for product development
Patrick Sheridan
 
Modern UI Architecture_ Trends and Technologies in Web Development
Modern UI Architecture_ Trends and Technologies in Web DevelopmentModern UI Architecture_ Trends and Technologies in Web Development
Modern UI Architecture_ Trends and Technologies in Web Development
Suresh Patidar
 
LA ATENCION
LA ATENCIONLA ATENCION
LA ATENCION
CSG
 
Barcelona presentacio tampere antirumors
Barcelona presentacio tampere antirumorsBarcelona presentacio tampere antirumors
Barcelona presentacio tampere antirumors
Thomas Jézéquel
 
Nana presentation
Nana presentationNana presentation
Nana presentation
cedarcon
 

Viewers also liked (11)

5 new rules for product development
5 new rules for product development5 new rules for product development
5 new rules for product development
 
Introducing type script
Introducing type scriptIntroducing type script
Introducing type script
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Modern UI Architecture_ Trends and Technologies in Web Development
Modern UI Architecture_ Trends and Technologies in Web DevelopmentModern UI Architecture_ Trends and Technologies in Web Development
Modern UI Architecture_ Trends and Technologies in Web Development
 
LA ATENCION
LA ATENCIONLA ATENCION
LA ATENCION
 
Barcelona presentacio tampere antirumors
Barcelona presentacio tampere antirumorsBarcelona presentacio tampere antirumors
Barcelona presentacio tampere antirumors
 
21071
2107121071
21071
 
Sencha Touch in Action
Sencha Touch in Action Sencha Touch in Action
Sencha Touch in Action
 
Teachertube
TeachertubeTeachertube
Teachertube
 
Ciao intro
Ciao introCiao intro
Ciao intro
 
Nana presentation
Nana presentationNana presentation
Nana presentation
 

Similar to JavaScript Secrets

Ruby goes to hollywood
Ruby goes to hollywoodRuby goes to hollywood
Ruby goes to hollywood
ehuard
 
Wireframes, User Interfaces, and User Experience
Wireframes, User Interfaces, and User Experience Wireframes, User Interfaces, and User Experience
Wireframes, User Interfaces, and User Experience
Erik Eliason
 
NodeJS, CoffeeScript & Real-time Web
NodeJS, CoffeeScript & Real-time WebNodeJS, CoffeeScript & Real-time Web
NodeJS, CoffeeScript & Real-time Web
Jakub Nesetril
 
The facilities of Features Drupal module
The facilities of Features Drupal moduleThe facilities of Features Drupal module
The facilities of Features Drupal module
Kálmán Hosszu
 
Collective Amberjack - European Plone Symposium
Collective Amberjack - European Plone SymposiumCollective Amberjack - European Plone Symposium
Collective Amberjack - European Plone Symposium
Massimo Azzolini
 
CMS Expo 2011 - Social Drupal
CMS Expo 2011 - Social DrupalCMS Expo 2011 - Social Drupal
CMS Expo 2011 - Social Drupal
Blake Hall
 

Similar to JavaScript Secrets (20)

Ruby goes to hollywood
Ruby goes to hollywoodRuby goes to hollywood
Ruby goes to hollywood
 
Drizzle 7.0, Future of Virtualizing
Drizzle 7.0, Future of VirtualizingDrizzle 7.0, Future of Virtualizing
Drizzle 7.0, Future of Virtualizing
 
Stackbox CMS: Next-Generation Content Management
Stackbox CMS: Next-Generation Content ManagementStackbox CMS: Next-Generation Content Management
Stackbox CMS: Next-Generation Content Management
 
Nodejs
NodejsNodejs
Nodejs
 
Wireframes, User Interfaces, and User Experience
Wireframes, User Interfaces, and User Experience Wireframes, User Interfaces, and User Experience
Wireframes, User Interfaces, and User Experience
 
Our Best Practices Are Killing Us
Our Best Practices Are Killing UsOur Best Practices Are Killing Us
Our Best Practices Are Killing Us
 
Drupal security - Configuration and process
Drupal security - Configuration and processDrupal security - Configuration and process
Drupal security - Configuration and process
 
The State of Front End Web Development 2011
The State of Front End Web Development 2011The State of Front End Web Development 2011
The State of Front End Web Development 2011
 
Pronk like you mean it
Pronk like you mean itPronk like you mean it
Pronk like you mean it
 
WordPress for ecommerce at wordcamp Indonesia 2011
WordPress for ecommerce at wordcamp Indonesia 2011WordPress for ecommerce at wordcamp Indonesia 2011
WordPress for ecommerce at wordcamp Indonesia 2011
 
Envato Dev Ops - Alt.Net Melbourne
Envato Dev Ops - Alt.Net MelbourneEnvato Dev Ops - Alt.Net Melbourne
Envato Dev Ops - Alt.Net Melbourne
 
Что нового в CSS3
Что нового в CSS3Что нового в CSS3
Что нового в CSS3
 
A Brief Intro to Angular.JS
A Brief Intro to Angular.JSA Brief Intro to Angular.JS
A Brief Intro to Angular.JS
 
Fuck Yeah Nouns
Fuck Yeah NounsFuck Yeah Nouns
Fuck Yeah Nouns
 
NodeJS, CoffeeScript & Real-time Web
NodeJS, CoffeeScript & Real-time WebNodeJS, CoffeeScript & Real-time Web
NodeJS, CoffeeScript & Real-time Web
 
The facilities of Features Drupal module
The facilities of Features Drupal moduleThe facilities of Features Drupal module
The facilities of Features Drupal module
 
Node js techtalksto
Node js techtalkstoNode js techtalksto
Node js techtalksto
 
Collective Amberjack - European Plone Symposium
Collective Amberjack - European Plone SymposiumCollective Amberjack - European Plone Symposium
Collective Amberjack - European Plone Symposium
 
Unit testing with Junit
Unit testing with JunitUnit testing with Junit
Unit testing with Junit
 
CMS Expo 2011 - Social Drupal
CMS Expo 2011 - Social DrupalCMS Expo 2011 - Social Drupal
CMS Expo 2011 - Social Drupal
 

More from Patrick Sheridan (8)

SenchaCon: Sencha Touch Custom Components
SenchaCon: Sencha Touch Custom Components SenchaCon: Sencha Touch Custom Components
SenchaCon: Sencha Touch Custom Components
 
Web audio app preso
Web audio app presoWeb audio app preso
Web audio app preso
 
Rvrsit
RvrsitRvrsit
Rvrsit
 
Javascript Performance Tricks
Javascript Performance TricksJavascript Performance Tricks
Javascript Performance Tricks
 
Discover Music
Discover MusicDiscover Music
Discover Music
 
ExtJS Forms
ExtJS FormsExtJS Forms
ExtJS Forms
 
Intro to sencha touch 2
Intro to sencha touch 2Intro to sencha touch 2
Intro to sencha touch 2
 
Javascript classes and scoping
Javascript classes and scopingJavascript classes and scoping
Javascript classes and scoping
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 

JavaScript Secrets

  • 1. JAVASCRIPT SECRETS Cleaner Code/ Faster Apps Wednesday, March 30, 2011
  • 2. About me • CTO, Modus Create. • RIA UI/UX design • High-end consulting • Training / workshops • Architectural guidance • Application architecture • Specialize in Sencha technologies. Wednesday, March 30, 2011
  • 7. AGENDA • Discuss some of the secrets behind JavaScript Wednesday, March 30, 2011
  • 8. 1995-2005 • Advance use of JavaScript was limited until ~ 2005 • Field validation • Mouse cursor trails • Right click preventers • Popup storms • Lots of books written • Many taught bad practices Wednesday, March 30, 2011
  • 9. Today? • JavaScript frameworks in use more • Do more, quicker! • Way better debug tools • Firebug • Webkit inspector • IE8 JS debug console (IE9 is a little better) • HTML5 is gaining popularity • Flash is (somewhat) threatened Wednesday, March 30, 2011
  • 10. It’s a JavaScript world! Wednesday, March 30, 2011
  • 12. Arithmetic • Arithmetic operators •+ (add/concatenate) •- (subtract) •* (multiplication) •/ (division) •% (modulus/remainder) Wednesday, March 30, 2011
  • 14. Remember • The + operator has a dual purpose • Addition and concatenation Wednesday, March 30, 2011
  • 15. Operator coercion • For -, *, / operators, • JavaScript will try to convert strings into numbers. Wednesday, March 30, 2011
  • 16. •When at all possible, try to perform math using numbers instead of strings. •This will help reduce the chance of errors. Wednesday, March 30, 2011
  • 18. Comparison operators with if/then • Most of us use if and then to control logic branches. • There is a hidden danger with == and != • Sometimes the result of an expression test can lead to unexpected code behavior Wednesday, March 30, 2011
  • 20. Meet “Falsy” and “Truthy” • Because JavaScript tries to coerce values, expressions using • == and != • Expressions are boiled down to “Falsy” and “Truthy” • There should be no room for “Falsy” and “Truthy” in your code. Wednesday, March 30, 2011
  • 22. Takeaway: == and != are EVIL Do not use them! Wednesday, March 30, 2011
  • 23. Instead... • Use === and !== • They are not evil :) • Get expected results every time • both === and !== test for value and data type • No coercion takes place Wednesday, March 30, 2011
  • 24. Fight the evil. All are false! Wednesday, March 30, 2011
  • 26. Hoisting •A mechanism for setting and creating things in a function when that function is executed. • When a function is executed, two passes are actually made on the function by the JavaScript interpreter. • It can lead to much pain when dealing with function statements. Wednesday, March 30, 2011
  • 27. How a function really is interpreted at execution time Wednesday, March 30, 2011
  • 28. How a function really is interpreted at execution time Wednesday, March 30, 2011
  • 30. More on hoisting • Due to hoisting, • function expressions • have their reference name created first and are assigned at execution time. • function statements • have their reference name created and are assigned before execution time Wednesday, March 30, 2011
  • 31. Function statement vs. expression Wednesday, March 30, 2011
  • 34. This should be impossible Wednesday, March 30, 2011
  • 35. Know hoisting.... • According to the hoisting rules, the second jump function should have been created • Firefox actually honors the conditional statement - what?! • Some browsers follow these rules and some don’t • This is because the language definition doesn’t really tell you what it’s supposed to do, so there are different implementations. • Coding this way can lead to unpredictable behavior of your Wednesday, March 30, 2011
  • 38. Asynchronous script tags • For HTML5 enabled browsers • Set async=‘async’ in your script tags. • <script type=‘text/javascript’ src=’/myfile.js’ async=‘async’></script> • Will allow JavaScript files to be non-blocking Wednesday, March 30, 2011
  • 39. Deferred execution • Set defer=‘defer’ in your script tags. • <script type=‘text/javascript’ src=’/myfile.js’ defer=‘defer’></script> • Will allow JavaScript code in those files to execute after the page has loaded. • Does not work in all browsers :( Wednesday, March 30, 2011
  • 41. Facts about minification • Reduce file size sent to the browser • Increase interpretation speed of JS files by the browser • Some Tools: • Yui-Compressor • Google Closure • Packer Wednesday, March 30, 2011
  • 42. A simple JS File • 183 Bytes Wednesday, March 30, 2011
  • 43. Minified • 103 Bytes • 44% savings Wednesday, March 30, 2011
  • 44. A better JS file • 184 Bytes Why is it better!?!? Wednesday, March 30, 2011
  • 45. ‘Better code’ === ‘more savings’ • 95 Bytes • 49% Savings Wednesday, March 30, 2011
  • 47. Loops Minifier can't claim space Namespace lookups costly Wednesday, March 30, 2011
  • 48. Faster loops Minifier friendly No initializer Faster Lookup Wednesday, March 30, 2011
  • 50. Less than optimal lookups Wednesday, March 30, 2011
  • 51. Less than optimal lookups Wednesday, March 30, 2011
  • 53. Recap •+ operators will concatenate strings, while -, *, / will coerce values • Avoid “Truthy” and “Falsy” by using === and !== • Use async and defer enabled Script tags when possible. • Use function expressions Wednesday, March 30, 2011
  • 54. Recap • Minify your code when possible • Develop “Minifier-friendly” code • Create optimized loops • Reduce namespace lookups by using local references Wednesday, March 30, 2011
  • 55. Thanks!!! Questions? Twitter: @_jdg Mobile: 301-785-3030 Web: moduscreate.com Email: jay@moduscreate.com Wednesday, March 30, 2011

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n