SlideShare a Scribd company logo
Building assets on the fly using
      node (no watcher)
            JS-Montreal




          Martin Drapeau
           2012-08-14
About Acquisio

• Automate web advertising


• The leading platform to buy, track,
 manage, optimize and report on                             Buy
 media across all major Search,
 Social and Display networks.
                                          Report                             Track
                                                          SEARCH
• Benefits                                                SOCIAL
   • Increase Efficiency                                  DISPLAY
   • Uncover New Business Opportunities
   • Serve Clients Better
                                               Optimize             Manage
   • Serve More Clients
   • Mitigate Risk



Visit www.acquisio.com for more info.
Current Front-End Technology Stack

• Flex (ActionScript)
   • EOL by Adobe


• Front-End Heavy
   • Client is +10MB (to be downloaded
     every time by customers)
   • Client contains a lot of business
     logic – heavy processing. A lot
     should be moved to the Back-End.


Need to change architecture!
Next Gen Front-End Technology Stack

                                          Javascript                                          Front-End
         -    MVC architecture                         -   Backbone JS & Underscore JS
         -    Presentation logic                       -   Twitter Bootstrap + Foundation     Efficient Development
                                                       -   Stylus for CSS (preprocessor)      - Zero compilation
                                                       -   Kendo UI for data-grid and other   - Dev in the browser
                                                           widgets                            - Re-use what’s out
                                                                                                   there



                          Apache/PHP                                 Node JS                  Serving
Private API




                                                           -   Build and deployment           Technologies
                -   Serve JS/CSS assets
                                                           -   JS dependency management
                -   Dynamic generation of HTML
                                                           -   Compilation of JS and CSS
                -   Harness for different
                                                           -   Test harness (unit,
                    environments (i.e. dev vs. prod)
                                                               functional and integration)

                                                               No communication
                                                               between PHP and Java


                                              Java                                            Service Layer
                           API & Business logic & Interface to Back-End                       “Middleware”
                                JBoss, JAX-RS (Jersey), JAXB (JSON)
Development in the browser

• Objective
  • Make it easy to develop in the browser
  • F5 must be the ONLY way to build


• How to do it
  • Harness PHP to manage assets on the fly


• Technology tools
   • Node.js – Driver our build scripts with JS!
   • Snockets – Manage JS dependencies, concat and minify
   • Stylus – CSS preprocessor
Managing JavaScript Assets

Snockets
• A JavaScript/CoffeeScript concatenation tool for Node.js
  inspired from Sprockets .
• We use it to manage dependencies and compile (concat and
  minify) production JS assets.

How to use (script-side)
• Declare dependencies directly in your JS files
       //= require jquery.js
or
       //= require_tree common
Managing JavaScript Assets

How to use (Node-side)

• Construct dependency chain
  var file = ‘my_file.js’;
  var dependencies = [];
  snockets.scan(file, {sync:1}, function(err, depGraph) {
    dependencies = depGraph.getChain(file);
  });


• Concatenate and minify (compilation)
  var file = ‘my_file.js’;
  snockets.getConcatenation(file, {minify:1, sync:1},
    function (err, js) {
      fs.writeFileSync(‘my_file.min.js’, js, 'utf8');});
    });
Managing CSS Assets

Stylus
• CSS preprocessor Expressive, dynamic, robust CSS

How to compile
• Use the Node.js stylus module.

  var file = ‘my_file.styl’;
  styl = fs.readFileSync(file, 'utf8').replace(/r/g, '');
  style = stylus(styl)
          .set('compress', true)
          .set('include css', true);
  style.render(function (err, css) {
    fs.writeFileSync('.css', css, 'utf8');
  });
PHP – Load JS assets

• Either load single minified JS file, or multiple JS files running
 Node.js to retrieve dependency chain

    function js($module) {
      if (USE_COMPILED_JS) {
        $this->view('script_include', array(
            'url' => WEB_ROOT."/javascripts/$module.min.js",
            'content_type' => 'text/javascript',
            'version' => VERSION
          ));
      } else {
        $assets = $this->getAssetsForJsModule($module);
        foreach ($assets as $asset)
          $this->view('script_include', $asset);
      }
    }
PHP – Load JS assets

• Run Node.js

  $chain_script = realpath(FCPATH.'../bin/js_chain.js');
  $cmd = 'node "'.$chain_script.'" '.$module;
  exec($cmd, $result);
  $chains = json_decode($result[0], TRUE);


• Create SCRIPT tags

  <script type="<?=$type?>" src="<?=$url?>"></script>
PHP – Load CSS assets

• If CSS files do not exist, or are stale – run Node.js to create
 them from Stylus files

  $stylus_script = realpath(FCPATH.'../bin/css_compile.js');
  $cmd = 'node "'.$stylus_script.'" --compress=true '.$module;
  exec($cmd, $result);
Performance in Development Environment

• JS Assets
   • 0.5 seconds to chain 70 dependencies (608KB raw JS)*


• CSS Assets
   • 1.7 seconds to compile 133 Stylus files (2.8MB) into 2 CSS files


• Time to Load page in Chrome

   With CSS Compilation
   92 requests ❘ 5.24MB transferred ❘ 5.75s (onload: 4.46s, DOMContentLoaded: 4.44s)

   With no CSS Compilation
   92 requests ❘ 5.24MB transferred ❘ 3.93s (onload: 2.57s, DOMContentLoaded: 2.55s)


 *Exculding 3rd party libraries jQuery and KendoUI
Other work in progress

• Automate builds with JavaScript thanks to Node.js!


• Deployment to different environments
  • QA, Staging, Pre-production and Production


• Automate running QA tests suites
   • Run QA unit, functional and integration tests
   • Use Zombie browser
Questions?

More Related Content

What's hot

Three WEM Dev Tricks
Three WEM Dev TricksThree WEM Dev Tricks
Three WEM Dev Tricks
Gabriel Walt
 
Single Page WebApp Architecture
Single Page WebApp ArchitectureSingle Page WebApp Architecture
Single Page WebApp Architecture
Morgan Cheng
 
Introduction to require js
Introduction to require jsIntroduction to require js
Introduction to require js
Ahmed Elharouny
 
Refactoring to a Single Page Application
Refactoring to a Single Page ApplicationRefactoring to a Single Page Application
Refactoring to a Single Page Application
Codemotion
 
AEM responsive
AEM responsiveAEM responsive
AEM responsive
Damien Antipa
 
Build your application in seconds and optimize workflow as much as you can us...
Build your application in seconds and optimize workflow as much as you can us...Build your application in seconds and optimize workflow as much as you can us...
Build your application in seconds and optimize workflow as much as you can us...
Alex S
 
Dynamic components using SPA concepts in AEM
Dynamic components using SPA concepts in AEMDynamic components using SPA concepts in AEM
Dynamic components using SPA concepts in AEM
Bojana Popovska
 
Deep dive into Vue.js
Deep dive into Vue.jsDeep dive into Vue.js
Deep dive into Vue.js
선협 이
 
Difference between jsf, servlet and jsp
Difference between jsf, servlet and jspDifference between jsf, servlet and jsp
Difference between jsf, servlet and jsp
Mindfire LLC
 
Drive dam
Drive damDrive dam
Drive dam
Gabriel Walt
 
Crx 2.2 Deep-Dive
Crx 2.2 Deep-DiveCrx 2.2 Deep-Dive
Crx 2.2 Deep-Dive
Gabriel Walt
 
AngularJS - Architecture decisions in a large project 
AngularJS - Architecture decisionsin a large project AngularJS - Architecture decisionsin a large project 
AngularJS - Architecture decisions in a large project 
Elad Hirsch
 
Webpack
WebpackWebpack
Build single page applications using AngularJS on AEM
Build single page applications using AngularJS on AEMBuild single page applications using AngularJS on AEM
Build single page applications using AngularJS on AEM
connectwebex
 
AngularJS with RequireJS
AngularJS with RequireJSAngularJS with RequireJS
AngularJS with RequireJS
Johannes Weber
 
Single Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJSSingle Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJS
M R Rony
 
iOS App Using cordova
iOS App Using cordovaiOS App Using cordova
iOS App Using cordova
Mitosis Technology
 
Bridging the Gap: Single-Page Apps and AEM
Bridging the Gap: Single-Page Apps and AEMBridging the Gap: Single-Page Apps and AEM
Bridging the Gap: Single-Page Apps and AEM
rbl002
 
Modular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSModular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJS
Gunnar Hillert
 
Umbraco Cape Town Meetup Presentation
Umbraco Cape Town Meetup PresentationUmbraco Cape Town Meetup Presentation
Umbraco Cape Town Meetup Presentation
Bluegrass Digital
 

What's hot (20)

Three WEM Dev Tricks
Three WEM Dev TricksThree WEM Dev Tricks
Three WEM Dev Tricks
 
Single Page WebApp Architecture
Single Page WebApp ArchitectureSingle Page WebApp Architecture
Single Page WebApp Architecture
 
Introduction to require js
Introduction to require jsIntroduction to require js
Introduction to require js
 
Refactoring to a Single Page Application
Refactoring to a Single Page ApplicationRefactoring to a Single Page Application
Refactoring to a Single Page Application
 
AEM responsive
AEM responsiveAEM responsive
AEM responsive
 
Build your application in seconds and optimize workflow as much as you can us...
Build your application in seconds and optimize workflow as much as you can us...Build your application in seconds and optimize workflow as much as you can us...
Build your application in seconds and optimize workflow as much as you can us...
 
Dynamic components using SPA concepts in AEM
Dynamic components using SPA concepts in AEMDynamic components using SPA concepts in AEM
Dynamic components using SPA concepts in AEM
 
Deep dive into Vue.js
Deep dive into Vue.jsDeep dive into Vue.js
Deep dive into Vue.js
 
Difference between jsf, servlet and jsp
Difference between jsf, servlet and jspDifference between jsf, servlet and jsp
Difference between jsf, servlet and jsp
 
Drive dam
Drive damDrive dam
Drive dam
 
Crx 2.2 Deep-Dive
Crx 2.2 Deep-DiveCrx 2.2 Deep-Dive
Crx 2.2 Deep-Dive
 
AngularJS - Architecture decisions in a large project 
AngularJS - Architecture decisionsin a large project AngularJS - Architecture decisionsin a large project 
AngularJS - Architecture decisions in a large project 
 
Webpack
WebpackWebpack
Webpack
 
Build single page applications using AngularJS on AEM
Build single page applications using AngularJS on AEMBuild single page applications using AngularJS on AEM
Build single page applications using AngularJS on AEM
 
AngularJS with RequireJS
AngularJS with RequireJSAngularJS with RequireJS
AngularJS with RequireJS
 
Single Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJSSingle Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJS
 
iOS App Using cordova
iOS App Using cordovaiOS App Using cordova
iOS App Using cordova
 
Bridging the Gap: Single-Page Apps and AEM
Bridging the Gap: Single-Page Apps and AEMBridging the Gap: Single-Page Apps and AEM
Bridging the Gap: Single-Page Apps and AEM
 
Modular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSModular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJS
 
Umbraco Cape Town Meetup Presentation
Umbraco Cape Town Meetup PresentationUmbraco Cape Town Meetup Presentation
Umbraco Cape Town Meetup Presentation
 

Similar to Building assets on the fly with Node.js

CQ5 and Sling overview
CQ5 and Sling overviewCQ5 and Sling overview
CQ5 and Sling overview
Bertrand Delacretaz
 
Wei ding(resume)
Wei ding(resume)Wei ding(resume)
Wei ding(resume)
WEI DING
 
Gubendran Lakshmanan
Gubendran LakshmananGubendran Lakshmanan
Gubendran Lakshmanan
Gubendran Lakshmanan
 
Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS
drupalcampest
 
Webpack Encore - Asset Management for the rest of us
Webpack Encore - Asset Management for the rest of usWebpack Encore - Asset Management for the rest of us
Webpack Encore - Asset Management for the rest of us
Stefan Adolf
 
Optimizing HTML5 Sites with CQ5/WEM
Optimizing HTML5 Sites with CQ5/WEMOptimizing HTML5 Sites with CQ5/WEM
Optimizing HTML5 Sites with CQ5/WEM
Gabriel Walt
 
Architecting non-trivial browser applications (Jazoon 2012)
Architecting non-trivial browser applications (Jazoon 2012)Architecting non-trivial browser applications (Jazoon 2012)
Architecting non-trivial browser applications (Jazoon 2012)
Marc Bächinger
 
Suresh_Resume
Suresh_ResumeSuresh_Resume
Suresh_Resume
Suresh Yekasiri
 
Building single page applications
Building single page applicationsBuilding single page applications
Building single page applications
SC5.io
 
(2018) Webpack Encore - Asset Management for the rest of us
(2018) Webpack Encore - Asset Management for the rest of us(2018) Webpack Encore - Asset Management for the rest of us
(2018) Webpack Encore - Asset Management for the rest of us
Stefan Adolf
 
AJAX Frameworks
AJAX FrameworksAJAX Frameworks
AJAX Frameworks
shank
 
Gangadhar_Challa_Profile
Gangadhar_Challa_ProfileGangadhar_Challa_Profile
Gangadhar_Challa_Profile
Gangadhar Challa
 
Intro to Sails.js
Intro to Sails.jsIntro to Sails.js
Intro to Sails.js
DevOpsDays Austin 2014
 
tonyz
tonyztonyz
tonyz
Tony Zhang
 
Enhancing Spring MVC Web Applications Progressively with Spring JavaScript
Enhancing Spring MVC Web Applications Progressively with Spring JavaScriptEnhancing Spring MVC Web Applications Progressively with Spring JavaScript
Enhancing Spring MVC Web Applications Progressively with Spring JavaScript
Jeremy Grelle
 
qooxdoo - Open Source Ajax Framework
qooxdoo - Open Source Ajax Frameworkqooxdoo - Open Source Ajax Framework
qooxdoo - Open Source Ajax Framework
ecker
 
Social Photos - My presentation at Microsoft Tech Day
Social Photos - My presentation at Microsoft Tech DaySocial Photos - My presentation at Microsoft Tech Day
Social Photos - My presentation at Microsoft Tech Day
TechMaster Vietnam
 
ITCamp 2012 - Alessandro Pilotti - Web API, web sockets and RSignal
ITCamp 2012 - Alessandro Pilotti - Web API, web sockets and RSignalITCamp 2012 - Alessandro Pilotti - Web API, web sockets and RSignal
ITCamp 2012 - Alessandro Pilotti - Web API, web sockets and RSignal
ITCamp
 
JSFoo-2017 Takeaways
JSFoo-2017 TakeawaysJSFoo-2017 Takeaways
JSFoo-2017 Takeaways
Mir Ali
 
Venkata
VenkataVenkata
Venkata
Venkata Kumar
 

Similar to Building assets on the fly with Node.js (20)

CQ5 and Sling overview
CQ5 and Sling overviewCQ5 and Sling overview
CQ5 and Sling overview
 
Wei ding(resume)
Wei ding(resume)Wei ding(resume)
Wei ding(resume)
 
Gubendran Lakshmanan
Gubendran LakshmananGubendran Lakshmanan
Gubendran Lakshmanan
 
Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS
 
Webpack Encore - Asset Management for the rest of us
Webpack Encore - Asset Management for the rest of usWebpack Encore - Asset Management for the rest of us
Webpack Encore - Asset Management for the rest of us
 
Optimizing HTML5 Sites with CQ5/WEM
Optimizing HTML5 Sites with CQ5/WEMOptimizing HTML5 Sites with CQ5/WEM
Optimizing HTML5 Sites with CQ5/WEM
 
Architecting non-trivial browser applications (Jazoon 2012)
Architecting non-trivial browser applications (Jazoon 2012)Architecting non-trivial browser applications (Jazoon 2012)
Architecting non-trivial browser applications (Jazoon 2012)
 
Suresh_Resume
Suresh_ResumeSuresh_Resume
Suresh_Resume
 
Building single page applications
Building single page applicationsBuilding single page applications
Building single page applications
 
(2018) Webpack Encore - Asset Management for the rest of us
(2018) Webpack Encore - Asset Management for the rest of us(2018) Webpack Encore - Asset Management for the rest of us
(2018) Webpack Encore - Asset Management for the rest of us
 
AJAX Frameworks
AJAX FrameworksAJAX Frameworks
AJAX Frameworks
 
Gangadhar_Challa_Profile
Gangadhar_Challa_ProfileGangadhar_Challa_Profile
Gangadhar_Challa_Profile
 
Intro to Sails.js
Intro to Sails.jsIntro to Sails.js
Intro to Sails.js
 
tonyz
tonyztonyz
tonyz
 
Enhancing Spring MVC Web Applications Progressively with Spring JavaScript
Enhancing Spring MVC Web Applications Progressively with Spring JavaScriptEnhancing Spring MVC Web Applications Progressively with Spring JavaScript
Enhancing Spring MVC Web Applications Progressively with Spring JavaScript
 
qooxdoo - Open Source Ajax Framework
qooxdoo - Open Source Ajax Frameworkqooxdoo - Open Source Ajax Framework
qooxdoo - Open Source Ajax Framework
 
Social Photos - My presentation at Microsoft Tech Day
Social Photos - My presentation at Microsoft Tech DaySocial Photos - My presentation at Microsoft Tech Day
Social Photos - My presentation at Microsoft Tech Day
 
ITCamp 2012 - Alessandro Pilotti - Web API, web sockets and RSignal
ITCamp 2012 - Alessandro Pilotti - Web API, web sockets and RSignalITCamp 2012 - Alessandro Pilotti - Web API, web sockets and RSignal
ITCamp 2012 - Alessandro Pilotti - Web API, web sockets and RSignal
 
JSFoo-2017 Takeaways
JSFoo-2017 TakeawaysJSFoo-2017 Takeaways
JSFoo-2017 Takeaways
 
Venkata
VenkataVenkata
Venkata
 

Recently uploaded

dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
Hiike
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
Dinusha Kumarasiri
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
saastr
 

Recently uploaded (20)

dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
 

Building assets on the fly with Node.js

  • 1. Building assets on the fly using node (no watcher) JS-Montreal Martin Drapeau 2012-08-14
  • 2. About Acquisio • Automate web advertising • The leading platform to buy, track, manage, optimize and report on Buy media across all major Search, Social and Display networks. Report Track SEARCH • Benefits SOCIAL • Increase Efficiency DISPLAY • Uncover New Business Opportunities • Serve Clients Better Optimize Manage • Serve More Clients • Mitigate Risk Visit www.acquisio.com for more info.
  • 3. Current Front-End Technology Stack • Flex (ActionScript) • EOL by Adobe • Front-End Heavy • Client is +10MB (to be downloaded every time by customers) • Client contains a lot of business logic – heavy processing. A lot should be moved to the Back-End. Need to change architecture!
  • 4. Next Gen Front-End Technology Stack Javascript Front-End - MVC architecture - Backbone JS & Underscore JS - Presentation logic - Twitter Bootstrap + Foundation Efficient Development - Stylus for CSS (preprocessor) - Zero compilation - Kendo UI for data-grid and other - Dev in the browser widgets - Re-use what’s out there Apache/PHP Node JS Serving Private API - Build and deployment Technologies - Serve JS/CSS assets - JS dependency management - Dynamic generation of HTML - Compilation of JS and CSS - Harness for different - Test harness (unit, environments (i.e. dev vs. prod) functional and integration) No communication between PHP and Java Java Service Layer API & Business logic & Interface to Back-End “Middleware” JBoss, JAX-RS (Jersey), JAXB (JSON)
  • 5. Development in the browser • Objective • Make it easy to develop in the browser • F5 must be the ONLY way to build • How to do it • Harness PHP to manage assets on the fly • Technology tools • Node.js – Driver our build scripts with JS! • Snockets – Manage JS dependencies, concat and minify • Stylus – CSS preprocessor
  • 6. Managing JavaScript Assets Snockets • A JavaScript/CoffeeScript concatenation tool for Node.js inspired from Sprockets . • We use it to manage dependencies and compile (concat and minify) production JS assets. How to use (script-side) • Declare dependencies directly in your JS files //= require jquery.js or //= require_tree common
  • 7. Managing JavaScript Assets How to use (Node-side) • Construct dependency chain var file = ‘my_file.js’; var dependencies = []; snockets.scan(file, {sync:1}, function(err, depGraph) { dependencies = depGraph.getChain(file); }); • Concatenate and minify (compilation) var file = ‘my_file.js’; snockets.getConcatenation(file, {minify:1, sync:1}, function (err, js) { fs.writeFileSync(‘my_file.min.js’, js, 'utf8');}); });
  • 8. Managing CSS Assets Stylus • CSS preprocessor Expressive, dynamic, robust CSS How to compile • Use the Node.js stylus module. var file = ‘my_file.styl’; styl = fs.readFileSync(file, 'utf8').replace(/r/g, ''); style = stylus(styl) .set('compress', true) .set('include css', true); style.render(function (err, css) { fs.writeFileSync('.css', css, 'utf8'); });
  • 9. PHP – Load JS assets • Either load single minified JS file, or multiple JS files running Node.js to retrieve dependency chain function js($module) { if (USE_COMPILED_JS) { $this->view('script_include', array( 'url' => WEB_ROOT."/javascripts/$module.min.js", 'content_type' => 'text/javascript', 'version' => VERSION )); } else { $assets = $this->getAssetsForJsModule($module); foreach ($assets as $asset) $this->view('script_include', $asset); } }
  • 10. PHP – Load JS assets • Run Node.js $chain_script = realpath(FCPATH.'../bin/js_chain.js'); $cmd = 'node "'.$chain_script.'" '.$module; exec($cmd, $result); $chains = json_decode($result[0], TRUE); • Create SCRIPT tags <script type="<?=$type?>" src="<?=$url?>"></script>
  • 11. PHP – Load CSS assets • If CSS files do not exist, or are stale – run Node.js to create them from Stylus files $stylus_script = realpath(FCPATH.'../bin/css_compile.js'); $cmd = 'node "'.$stylus_script.'" --compress=true '.$module; exec($cmd, $result);
  • 12. Performance in Development Environment • JS Assets • 0.5 seconds to chain 70 dependencies (608KB raw JS)* • CSS Assets • 1.7 seconds to compile 133 Stylus files (2.8MB) into 2 CSS files • Time to Load page in Chrome With CSS Compilation 92 requests ❘ 5.24MB transferred ❘ 5.75s (onload: 4.46s, DOMContentLoaded: 4.44s) With no CSS Compilation 92 requests ❘ 5.24MB transferred ❘ 3.93s (onload: 2.57s, DOMContentLoaded: 2.55s) *Exculding 3rd party libraries jQuery and KendoUI
  • 13. Other work in progress • Automate builds with JavaScript thanks to Node.js! • Deployment to different environments • QA, Staging, Pre-production and Production • Automate running QA tests suites • Run QA unit, functional and integration tests • Use Zombie browser