SlideShare a Scribd company logo
1 of 14
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 TricksGabriel Walt
 
Single Page WebApp Architecture
Single Page WebApp ArchitectureSingle Page WebApp Architecture
Single Page WebApp ArchitectureMorgan Cheng
 
Introduction to require js
Introduction to require jsIntroduction to require js
Introduction to require jsAhmed Elharouny
 
Refactoring to a Single Page Application
Refactoring to a Single Page ApplicationRefactoring to a Single Page Application
Refactoring to a Single Page ApplicationCodemotion
 
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 AEMBojana 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 jspMindfire LLC
 
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
 
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 AEMconnectwebex
 
AngularJS with RequireJS
AngularJS with RequireJSAngularJS with RequireJS
AngularJS with RequireJSJohannes Weber
 
Single Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJSSingle Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJSM R Rony
 
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 AEMrbl002
 
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 AngularJSGunnar Hillert
 
Umbraco Cape Town Meetup Presentation
Umbraco Cape Town Meetup PresentationUmbraco Cape Town Meetup Presentation
Umbraco Cape Town Meetup PresentationBluegrass 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

Wei ding(resume)
Wei ding(resume)Wei ding(resume)
Wei ding(resume)WEI DING
 
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 usStefan Adolf
 
Optimizing HTML5 Sites with CQ5/WEM
Optimizing HTML5 Sites with CQ5/WEMOptimizing HTML5 Sites with CQ5/WEM
Optimizing HTML5 Sites with CQ5/WEMGabriel 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
 
Building single page applications
Building single page applicationsBuilding single page applications
Building single page applicationsSC5.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 usStefan Adolf
 
AJAX Frameworks
AJAX FrameworksAJAX Frameworks
AJAX Frameworksshank
 
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 JavaScriptJeremy Grelle
 
qooxdoo - Open Source Ajax Framework
qooxdoo - Open Source Ajax Frameworkqooxdoo - Open Source Ajax Framework
qooxdoo - Open Source Ajax Frameworkecker
 
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 DayTechMaster 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 RSignalITCamp
 
JSFoo-2017 Takeaways
JSFoo-2017 TakeawaysJSFoo-2017 Takeaways
JSFoo-2017 TakeawaysMir Ali
 

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

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 

Recently uploaded (20)

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 

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