SlideShare a Scribd company logo
Production Ready JavaScript
Sanjay Krishna Anbalagan
Production Ready
Webpack
Production Ready
Webpack
Production Ready
Build a Bundler from Scratch
Webpack
2000
Production Ready
File
Size
Request
RequestResponse
Server Memory to Browser Run time Memory
RequestResponse
Server Memory to Browser Run time Memory
RequestResponse
Issues:
1. File Size ?
Reduce Variable Name Length
Reduce Variable Name Length
Remove White Spaces and trailing Spaces
Reduce Variable Name Length
Remove White Spaces and trailing Spaces
Reduce Variable Name Length
Remove White Spaces and trailing Spaces
Issues:
1. File Size ? Minified File …..!!!!!
Server Memory to Browser Run time Memory
RequestResponse
Issues:
1. File Size ? Minified File …..!!!!!
2. Multiple File ?
Server Memory to Browser Run time Memory
RequestResponse
Issues:
1. File Size ? Minified File …..!!!!!
2. Multiple File ? Combine Files …..!!!!!
Server Memory to Browser Run time Memory
RequestResponse
Issues:
1. File Size ? Minified File …..!!!!!
2. Multiple File ? Combine Files …..!!!!!
Server Memory to Browser Run time Memory
RequestResponse
2015
Client Browser
JS Version
2015
Developers Problem
Polluting Global Scope
Polluting Global Scope
IIFE Pattern
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression => Module Pattern
IIFE: Immediately Invoked Function Expression => Module Pattern
IIFE: Immediately Invoked Function Expression => Module Pattern
IIFE: Immediately Invoked Function Expression => Module Pattern
IIFE: Immediately Invoked Function Expression => Module Pattern
IIFE: Immediately Invoked Function Expression => Module Pattern
IIFE: Immediately Invoked Function Expression => Module Pattern
IIFE: Immediately Invoked Function Expression => Module Pattern
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
IIFE: Immediately Invoked Function Expression
2020
Issues:
1. File Size ? Minified File …..!!!!!
2. Multiple File ? Combine Files …..!!!!!
Server Memory to Browser Run time Memory
RequestResponse
Issues:
1. File Size ? Minified File …..!!!!!
2. Multiple File ? Combine Files …..!!!!!
Server Memory to Browser Run time Memory
RequestResponse
Issues:
1. File Size ? Minified File …..!!!!!
2. Multiple File ? Bundled Files ….!!!!
Server Memory to Browser Run time Memory
RequestResponse
Demo

More Related Content

Similar to Webpack Internals - Bundle - Production Ready JS

Source Control 101
Source Control 101Source Control 101
Source Control 101
Robert MacLean
 
Yahoo! Developer Networks ♥ Startups
Yahoo! Developer Networks ♥ StartupsYahoo! Developer Networks ♥ Startups
Yahoo! Developer Networks ♥ Startups
Tom Croucher
 
Innovateeurope
InnovateeuropeInnovateeurope
Innovateeurope
Tom Croucher
 
Javacro 2014 Spring Security 3 Speech
Javacro 2014 Spring Security 3 SpeechJavacro 2014 Spring Security 3 Speech
Javacro 2014 Spring Security 3 Speech
Fernando Redondo Ramírez
 
Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku
Rapid Prototyping Chatter with a PHP/Hack Canvas App on HerokuRapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku
Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku
Salesforce Developers
 
presentation
presentationpresentation
presentation
aaron bishop
 
Be a library developer!
Be a library developer!Be a library developer!
Be a library developer!
Kouhei Sutou
 
Develop:BBC 2013 - Turbocharge your mobile web apps by using offline
Develop:BBC 2013 - Turbocharge your mobile web apps by using offlineDevelop:BBC 2013 - Turbocharge your mobile web apps by using offline
Develop:BBC 2013 - Turbocharge your mobile web apps by using offline
Jan Jongboom
 
10 practices that every developer needs to start right now
10 practices that every developer needs to start right now10 practices that every developer needs to start right now
10 practices that every developer needs to start right now
Caleb Jenkins
 
JavaScript tools
JavaScript toolsJavaScript tools
JavaScript tools
Hazem Saleh
 
Browser Automation - NTC 2010
Browser Automation - NTC 2010Browser Automation - NTC 2010
Browser Automation - NTC 2010
Ehren Foss
 
The Scientific Filesystem
The Scientific FilesystemThe Scientific Filesystem
The Scientific Filesystem
Vanessa S
 
BPM-4 Migration from jBPM to Activiti
BPM-4 Migration from jBPM to ActivitiBPM-4 Migration from jBPM to Activiti
BPM-4 Migration from jBPM to Activiti
Alfresco Software
 
Don't screw it up! How to build durable API
Don't screw it up! How to build durable API Don't screw it up! How to build durable API
Don't screw it up! How to build durable API
Alessandro Cinelli (cirpo)
 
Games for the Masses (Jax)
Games for the Masses (Jax)Games for the Masses (Jax)
Games for the Masses (Jax)
Wooga
 
presentation
presentationpresentation
presentation
Peter Oswald
 
How Heroku uses Heroku to build Heroku
How Heroku uses Heroku to build HerokuHow Heroku uses Heroku to build Heroku
How Heroku uses Heroku to build Heroku
Craig Kerstiens
 
Continous Delivering a PHP application
Continous Delivering a PHP applicationContinous Delivering a PHP application
Continous Delivering a PHP application
Javier López
 
Reducing passive interruptions
Reducing passive interruptionsReducing passive interruptions
Reducing passive interruptions
Andrei Tognolo
 
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
Fabien Potencier
 

Similar to Webpack Internals - Bundle - Production Ready JS (20)

Source Control 101
Source Control 101Source Control 101
Source Control 101
 
Yahoo! Developer Networks ♥ Startups
Yahoo! Developer Networks ♥ StartupsYahoo! Developer Networks ♥ Startups
Yahoo! Developer Networks ♥ Startups
 
Innovateeurope
InnovateeuropeInnovateeurope
Innovateeurope
 
Javacro 2014 Spring Security 3 Speech
Javacro 2014 Spring Security 3 SpeechJavacro 2014 Spring Security 3 Speech
Javacro 2014 Spring Security 3 Speech
 
Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku
Rapid Prototyping Chatter with a PHP/Hack Canvas App on HerokuRapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku
Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku
 
presentation
presentationpresentation
presentation
 
Be a library developer!
Be a library developer!Be a library developer!
Be a library developer!
 
Develop:BBC 2013 - Turbocharge your mobile web apps by using offline
Develop:BBC 2013 - Turbocharge your mobile web apps by using offlineDevelop:BBC 2013 - Turbocharge your mobile web apps by using offline
Develop:BBC 2013 - Turbocharge your mobile web apps by using offline
 
10 practices that every developer needs to start right now
10 practices that every developer needs to start right now10 practices that every developer needs to start right now
10 practices that every developer needs to start right now
 
JavaScript tools
JavaScript toolsJavaScript tools
JavaScript tools
 
Browser Automation - NTC 2010
Browser Automation - NTC 2010Browser Automation - NTC 2010
Browser Automation - NTC 2010
 
The Scientific Filesystem
The Scientific FilesystemThe Scientific Filesystem
The Scientific Filesystem
 
BPM-4 Migration from jBPM to Activiti
BPM-4 Migration from jBPM to ActivitiBPM-4 Migration from jBPM to Activiti
BPM-4 Migration from jBPM to Activiti
 
Don't screw it up! How to build durable API
Don't screw it up! How to build durable API Don't screw it up! How to build durable API
Don't screw it up! How to build durable API
 
Games for the Masses (Jax)
Games for the Masses (Jax)Games for the Masses (Jax)
Games for the Masses (Jax)
 
presentation
presentationpresentation
presentation
 
How Heroku uses Heroku to build Heroku
How Heroku uses Heroku to build HerokuHow Heroku uses Heroku to build Heroku
How Heroku uses Heroku to build Heroku
 
Continous Delivering a PHP application
Continous Delivering a PHP applicationContinous Delivering a PHP application
Continous Delivering a PHP application
 
Reducing passive interruptions
Reducing passive interruptionsReducing passive interruptions
Reducing passive interruptions
 
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
 

Recently uploaded

Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 

Recently uploaded (20)

Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 

Webpack Internals - Bundle - Production Ready JS

Editor's Notes

  1. Hello Everyone, When we say production Ready JavaScript in 2020, the word that strike our mind is
  2. Webpack
  3. In this video we are not going to learn about Webpack, instead
  4. We are going to build a basic bundler from scratch. In order to that, let travel two decades back
  5. We are in 2000, hmmmm, what does it mean ? when we say production ready JavaScript in 2000.
  6. File Size ….. Why ? Let address that with an example
  7. Back then Web Application is Purely back end work, JavaScript was primarily used as code snippets. Here is an example , A HTML page, Which displays current data and time, when we click the button. We developers want to keep the code clean by abstract the logic from HTML How do we do that ?
  8. Let move the logic from INLINE to Script Tag
  9. We defined the logic in a function inside script tag
  10. And we subscribed that function for button click Cool. This looks clean, How about taking this logic to a separate file ?
  11. Here we moved this logic to a separate file myscripts.js
  12. Aha, Now we had to worry about our javaScript file Size. Why ? When our browser request for this file, loading time of this file depends on its size
  13. Here our browser makes a request
  14. Server responds back with a copy of this Javscript file. Which is stored in
  15. Browser Run time Memory.
  16. So file Size matters in terms of download time and Client Memory. Let see this with an example
  17. Hers is our file, who size is
  18. 100 Bytes
  19. To reduce our file size, lets reduce the length of our function name and variable name here
  20. Here we replaced function name ‘displayDateAndTime’ with ‘f’ And variable name ‘date’ with ‘e’
  21. Awesome, what else we can do here?
  22. hmm….. lets remove white space and trailing spaces, And check our file size again
  23. Wow, we did it … We could bring down our file size to 75 bytes from 100 bytes.
  24. This Minified File is our Production Ready Javscript
  25. Did it end there ? No Now We want to abstract each logic to its respective file,
  26. So our next issue is handling multiple files.
  27. What we did here is, we combined both the files as a single file
  28. And minified them
  29. And now our production ready javaScript is Combined and Minified File
  30. Awesome now we are in 2015, we successfully created production ready javaScript. Wait, what happened now.
  31. The JavaScript community too grown now , new features started coming to Javscript language. Wait does that mean all our client machine needs to update to latest browser ? Wont that be stupid, do I need to ask my grand parents to install latest browser? Are there any other solution ? …….. Yes it Let start with an example to address this
  32. Hers is an example with two new javaScript features Default value for Arguments New Syntax let These two new feature will fail in my grandparents browser.
  33. To fix that, we need to rewrite the same logic in old feature we moved onlyTime argument as variable inside the function with default value fale We replaced let with var.
  34. This we call as transpillers Babel is one of the most actively used tranpilers tools.
  35. Now We combine files
  36. Into a single file
  37. Traspile them to common version
  38. And finally we minify them
  39. Now our Production ready JavaScript is Combined, Transpilled and Minified
  40. With more and more logic moving to JavaScript. Developers started facing their biggest nightmare,
  41. Global Scope Pollution
  42. Let me explain . When our file gets executed by JavaScript engine
  43. They start creating new property to window object. Wait … Why this would be problem ? Imagine, we have 10 files, and each file has 4 function, Developers had to make sure, they have to create unique-Names for each variables And if it’s a distributed team of developers, a team might end up overriding a function with the same name This will be a nightmare to debug and track the problem. Hmmm Do we have solution ? Yes of course,
  44. IIFE … Pattern, Wow what is that ?
  45. let say we have two files file1 – has getdate Definition File2 – has displayDateTime definition I want everyone to closely follow from here, Hope everyone could see this faded abbreviation of IIFE, in the top I am going to reveal each word in this abbreviation with its respective step in code, Let start with the first step
  46. Wrap our code with an anonymous function . Hmm Why Anonymous function ? When our javaScript engine execute this function definition , they don’t create new property in our window object., why ? because this function don’t have a name, Wait wait, when there is no function name how are we going to invoke it, hmm, you will get your answer in next step
  47. Wrap our anonymous function with an expression. Why ? Remember we had to invoke this Anonymous function, What we had was function declaration , if we invoke them JS engine will throw you an syntax error, So we have to convert the function Declaration to an Function Expression There are several tricks to achieve that, But we will go with brackets From now on I am going to address each file as Function Expression Now that we understood the purpose of expression, lets utitlize it, Let invoke in next step
  48. There you go, you got the purpose and meaning of each word in IIFE Pattern; Immediately invoked function Expression Ok what does this achieve ? How does this solve our global pollution issue ? When JS Engine execute: invoking Function Expression, your code inside the expression get called So variable in our code will be defined inside the inner scope of this Anonymous function expression. Not at the global scope So what we achieved here is separate inner scope with IIFE pattern; Means Our JavaScript programs are split into separate scope on its own.
  49. This is called module. … When we invoke a function expression we end up creating module. This might make you think, When there are not defined in global Scope, how these Function Expressions are going to communicate ? That’s what we are going to solve next
  50. In our Example , Function Expression 2, calls the function getDate(), which will throw an error . Why ? 1. getDate is not defined in diaplyDateAndTime 2. If we check In its outer scope – which is an anonmynous function, - not defined there either 3. If we check in outer scope of anonmynous function which is the global scope, window object, not defined there too, so its throws an error By the way This is called scope chain . Function with scope chain is called Closure … Now we can say, getDate is called inside the closure of displayDateAndTime.
  51. Now what we see here is a dependency issue, How do we solve this? What we need here is a way to export variable or functions or constant outside a Module And Import in the Consumer when needed. In this Example We need a way to export getDate out of function Expression 1 And import getDate function inside function expression 2. In general What we propose here is , every function Expression should have the ability to export and import let resolve that next.
  52. let pass two arguments to each Function Expression, exports to export its variable Require to import variables
  53. Let make exports to be an object which hold the variables , functions or constant that needs to be exposed Since Export being an Object, inorder to consume this Object, we need a getter. Yes your guess is Right … require will be our getter function, Which will give us the exports object Here we go
  54. Hmmm, What will be the basic requirement for a getter function KEY ---- in our case, since file path are unique , we will make file Path as our key Now Where does this require gets defined ?
  55. Let call that as module Manger, Before Implementing Module Manger, let see the purpose of module manger
  56. Say we have an Object
  57. Whose key is file path
  58. And its value being an Function Expression
  59. Code inside that function expression will be you file
  60. As minified version
  61. Now for file 2
  62. In file 3 , we Have three functions that are exported createButton - which adds button to your page createPara – which add Para Element to your page addListener – which attaches an eventListener for Button Click Event
  63. Now index.js Which exprts three function from file 3 And Invokes them
  64. Our Purpose here is to convert this Object of Function Expressions into an Object of Exports
  65. Now Implementation Lets start by creating an Anonymous Function Why ? We don’t want to be part of global Scope This Function takes in Function Expression Object
  66. And now we need ModuleExports Object to stored the exports returned by invoking respective Func Exp
  67. Now we get to the meat, Definition of require
  68. First step let check in module exports Object, If it not there
  69. Create an empty Object named exports Now we need to populate the exports oBject for that fiepath How?
  70. Get the function Expression for that filePath
  71. And Invoke them This will populate the Exports Object
  72. Now return that exports Object Now where and How do we invoke this require function, to populate ModuleExports Object
  73. We need to call inside our Module Manger We need a FilePath that needs to be the Starting point of our function Expressions Object
  74. Lets name that as entry Now we need to Invoke this module Manager How ? …. Yes your guess is right
  75. Wrap them with Expression
  76. And We need to invoke them with our Function-Expression Object
  77. And next we need an entry point
  78. In our case, index.js file Let's do a code walk through to understand better
  79. In our case, index.js file Let's do a code walk through to understand better
  80. In our case, index.js file Let's do a code walk through to understand better
  81. In our case, index.js file Let's do a code walk through to understand better
  82. var moduleManger = (function (funcExpressions, entry) { var moduleExports = {}; function require(id) { var exports = moduleExports[id]; if(exports){ return exports; } exports = moduleExports[id] = {}; var funcExp = funcExpressions[id]; funcExp(exports, require); return exports; } require(entry); }) var fileAsFunExpressions = { "./file1.js": (function(exports, require){ function f(){ return Date(); }; exports['getDate'] = f; }), "./file2.js": (function(exports, require){ var g = require("./file1.js").getDate; function d(p){ p.innerHTML = g() }; exports['displayDateTime'] = d; }), "./file3.js": (function(exports, require){ var d = require("./file2.js").displayDateTime; var b = document.body; var bt, t, p; function cb(){ bt = document.createElement("button"); t = document.createTextNode("Display Time"); bt.appendChild(t); b.appendChild(bt); }; function cp(){ p = document.createElement("p"); b.appendChild(p); }; function a(){ bt.addEventListener("click", ()=>d(p)); }; exports['createButton'] = cb; exports['createPara'] = cp; exports['addListener'] = a; }), "./index.js": (function(exports, require){ var me = require("./file3.js"); me.createButton(); me.createPara(); me.addListener(); }) } moduleManger(fileAsFunExpressions, './index.js')