SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Downloaden Sie, um offline zu lesen
JavaScript and Python
                           back-end
                           Max Klymyshyn
                              oDesk PS

                           Twitter: @maxmaxmaxmax
                                  Github: joymax
                                      Sources:
                           goo.gl/zbtXH
Saturday, March 24, 12                              1
The problem

                     JavaScript code grew up on the Project
                     Optimization of the Application become the pain in the ass
                     Hard to manage dependencies and test updates



Saturday, March 24, 12                                                            2
The solution


                     Add Assets Management tools to the project
                     Define and follow conventions




Saturday, March 24, 12                                            3
TOC
                     Project Structure
                     Assets management
                     JavaScript Templates
                     Constants within JS files
                     Browser-specific assets
                     SCSS/LESS
Saturday, March 24, 12                          4
Note


                     This presentation based on Flask but it's possible to
                     use Django or any other framework which
                     supported by Webassets



Saturday, March 24, 12                                                       5
Project structure
                 •       app.py
                 •       assets.py
                           • templates
                                • base.html
                           • bundles
                                • browsers.py
                                • jstemplates.py
                                • scss_bundle.py
                                • vars.py
                           • static
                                • src
                                     • js
                                     • css
                                • js
                           • css


Saturday, March 24, 12                             6
Assets management
    core = Bundle(
            "src/js/lib/core/*.js",
            "src/js/lib/*.js",
            output="core.js"
    )


    assets.register("js_core", core)


Saturday, March 24, 12                   7
JavaScript Templates
                   var %(namespace)s = %(namespace)s || {};
                   %(namespace)s._assign = function (obj, keyPath, value) {
                      var lastKeyIndex = keyPath.length - 1;
                      for (var i = 0; i < lastKeyIndex; i++) {
                          key = keyPath[i];
                          if (typeof obj[key] === "undefined") { obj[key] = {}; }
                          obj = obj[key];
                       }
                       obj[keyPath[lastKeyIndex]] = value;
                   };
                   (function(){
                    // ... here should be templates definitions
                    })();

Saturday, March 24, 12                                                             8
JavaScript templates
         templates = (
           'system/*.tpl',
           'views/main/*.tpl',
           'views/group/*.tpl',
           'views/rate/*.tpl',
           'views/search/*.tpl',
           'views/sort/*.tpl',
           'views/progress/*.tpl',
           'views/sidebar/listings/*.tpl',
           'views/sidebar/search/*.tpl',
         )



Saturday, March 24, 12                       9
Constants within JavaScript
             def constants(app):
               cfg = {}
               with app.test_request_context():
                  cfg.update(dict(
                     API_URL=url_for("api", _external=True),
                     TITLE="Sample Widget"
                  ))
               return cfg


             conf_app = JSVarsBundle("src/js/conf/main.js",
               output="js/compiled/conf/conf.js",
               vars=constants(app),
               filters=[“yui_js”],
               ignore_filters=assets.debug
             )

Saturday, March 24, 12                                         10
Constants within JavaScript
                     Configuration file looks like:
             ...

                     _.defaults(config, {
                         'api_url': '$$API_URL',
                         'title': '$$TITLE'
                     });

                     window.KHARKIVPY.config = config;



Saturday, March 24, 12                                 11
Browser-specific assets


                     We need to load custom assets for different browsers
                     We don’t have ability to use conditional commends for IEs
                     (business requirement)



Saturday, March 24, 12                                                           12
Browser-specific assets
                 chrome17 = BrowserBundle(
                   'src/css/browsers/chrome17.css',
                   browser='Chrome', browser_version='17',
                   output='css/chrome17.css'
                 )
           ...
                 browserspec_assets_loader = LoaderBrowserBundle(
                   'src/css/browsers/safari5.css', # dirty hack, we’ll change it
                   bundles=[chrome17, safari5],
                   filters='loader_browser',
                   output='js/compiled/assets-loader.js'
                 )

                 assets.register(
                   "browserspec_assets_loader",
                   browserspec_assets_loader)

Saturday, March 24, 12                                                             13
Browser-specific assets
                     Below is generated snippet by webassets bundle:

             (function (assets) {
                 BrowserAssets('/static/', assets);
             })({
             'Chrome': {
               '17': ['src/css/browsers/chrome17.css']},
             'Safari': {
               '5.1': ['src/css/browsers/safari5.css']}
             });

Saturday, March 24, 12                                                 14
SCSS/LESS

                     It was painful to maintain raw CSS for complex public
                     widget
                     We declined to use LESS because we aren’t found good and
                     maintainable LESS compiler for Python
                     We decided to not use client-side LESS parser to avoid
                     possible conflicts with client’s code

Saturday, March 24, 12                                                          15
SCSS/LESS
         style_files = (
            'reset.scss',
            'base.scss',
         )

         register_scss_bundle(
           style_files,
           assets=assets,
           name='css_core',
           output='css/style.css',
           prefix='src/css',
           compile_to='css/compiled'
         )
Saturday, March 24, 12                 16
CDN (Amazon CloudFront)

                     Sometimes back-end server goes down
                     Clients and partners may experience really weird behavior
                     and look of the Widget when back-end not available
                     No one want to loose face in front of the client



Saturday, March 24, 12                                                           17
CDN (Amazon CloudFront)

                     All of static related to the Widget hosted on Amazon
                     CloudFront
                     In case back-end goes down for maintenance or because of
                     failure JavaScript display nice error
                     Widget still looks like it should


Saturday, March 24, 12                                                          18
CDN Pitfalls

                     Amazon CloudFront may update your files REALLY SLOW
                     It may take up to 24 hrs to spread updates to all CDN nodes
                     around the world
                     You may experience hard time with your product owner
                     CDN is for really patient clients


Saturday, March 24, 12                                                             19
Questions?


Saturday, March 24, 12                20
Saturday, March 24, 12   21

Weitere ähnliche Inhalte

Was ist angesagt?

Ajax Performance Tuning and Best Practices
Ajax Performance Tuning and Best PracticesAjax Performance Tuning and Best Practices
Ajax Performance Tuning and Best Practices
Doris Chen
 

Was ist angesagt? (13)

CCI2018 - Automatizzare la creazione di risorse con ARM template e PowerShell
CCI2018 - Automatizzare la creazione di risorse con ARM template e PowerShellCCI2018 - Automatizzare la creazione di risorse con ARM template e PowerShell
CCI2018 - Automatizzare la creazione di risorse con ARM template e PowerShell
 
Azure Day Reloaded 2019 - ARM Template workshop
Azure Day Reloaded 2019 - ARM Template workshopAzure Day Reloaded 2019 - ARM Template workshop
Azure Day Reloaded 2019 - ARM Template workshop
 
Backbone
BackboneBackbone
Backbone
 
BackboneJs
BackboneJsBackboneJs
BackboneJs
 
Dandelion 0.10.0
Dandelion 0.10.0Dandelion 0.10.0
Dandelion 0.10.0
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
 
Karine bosch caching-spsbe14
Karine bosch caching-spsbe14Karine bosch caching-spsbe14
Karine bosch caching-spsbe14
 
Jaxitalia09 Spring Best Practices
Jaxitalia09 Spring Best PracticesJaxitalia09 Spring Best Practices
Jaxitalia09 Spring Best Practices
 
The new static resources framework
The new static resources frameworkThe new static resources framework
The new static resources framework
 
Ajax Performance Tuning and Best Practices
Ajax Performance Tuning and Best PracticesAjax Performance Tuning and Best Practices
Ajax Performance Tuning and Best Practices
 
Backbonejs for beginners
Backbonejs for beginnersBackbonejs for beginners
Backbonejs for beginners
 
Grails resources
Grails resourcesGrails resources
Grails resources
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 

Andere mochten auch

Java script at backend nodejs
Java script at backend   nodejsJava script at backend   nodejs
Java script at backend nodejs
Amit Thakkar
 

Andere mochten auch (6)

Philly Tech Week Introduction to NodeJS
Philly Tech Week Introduction to NodeJSPhilly Tech Week Introduction to NodeJS
Philly Tech Week Introduction to NodeJS
 
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, DhakaJavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
 
Java script at backend nodejs
Java script at backend   nodejsJava script at backend   nodejs
Java script at backend nodejs
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 

Ähnlich wie Kharkivpy#3: Javascript and Python backend

Web applications with Catalyst
Web applications with CatalystWeb applications with Catalyst
Web applications with Catalyst
svilen.ivanov
 
Module, AMD, RequireJS
Module, AMD, RequireJSModule, AMD, RequireJS
Module, AMD, RequireJS
偉格 高
 

Ähnlich wie Kharkivpy#3: Javascript and Python backend (20)

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
 
lecture5
lecture5lecture5
lecture5
 
lecture5
lecture5lecture5
lecture5
 
Web applications with Catalyst
Web applications with CatalystWeb applications with Catalyst
Web applications with Catalyst
 
Drupal Javascript for developers
Drupal Javascript for developersDrupal Javascript for developers
Drupal Javascript for developers
 
RequireJS
RequireJSRequireJS
RequireJS
 
Asset management with Zend Framework 2
Asset management with Zend Framework 2Asset management with Zend Framework 2
Asset management with Zend Framework 2
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
大規模サイトにおけるユーザーレベルのキャッシュ活用によるパフォーマンスチューニング
大規模サイトにおけるユーザーレベルのキャッシュ活用によるパフォーマンスチューニング大規模サイトにおけるユーザーレベルのキャッシュ活用によるパフォーマンスチューニング
大規模サイトにおけるユーザーレベルのキャッシュ活用によるパフォーマンスチューニング
 
RoR 101: Session 6
RoR 101: Session 6RoR 101: Session 6
RoR 101: Session 6
 
Styling components with JavaScript
Styling components with JavaScriptStyling components with JavaScript
Styling components with JavaScript
 
Single Page JavaScript WebApps... A Gradle Story
Single Page JavaScript WebApps... A Gradle StorySingle Page JavaScript WebApps... A Gradle Story
Single Page JavaScript WebApps... A Gradle Story
 
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep Dive
 
Gradle
GradleGradle
Gradle
 
Deploying Machine Learning Models to Production
Deploying Machine Learning Models to ProductionDeploying Machine Learning Models to Production
Deploying Machine Learning Models to Production
 
RoR 101: Session 6
RoR 101: Session 6RoR 101: Session 6
RoR 101: Session 6
 
Styling Components with JavaScript: MelbCSS Edition
Styling Components with JavaScript: MelbCSS EditionStyling Components with JavaScript: MelbCSS Edition
Styling Components with JavaScript: MelbCSS Edition
 
Droidcon Paris 2015
Droidcon Paris 2015Droidcon Paris 2015
Droidcon Paris 2015
 
Module, AMD, RequireJS
Module, AMD, RequireJSModule, AMD, RequireJS
Module, AMD, RequireJS
 

Mehr von Max Klymyshyn

Зачем читать чужой код?
Зачем читать чужой код?Зачем читать чужой код?
Зачем читать чужой код?
Max Klymyshyn
 

Mehr von Max Klymyshyn (20)

Papers We Love Kyiv, July 2018: A Conflict-Free Replicated JSON Datatype
Papers We Love Kyiv, July 2018: A Conflict-Free Replicated JSON DatatypePapers We Love Kyiv, July 2018: A Conflict-Free Replicated JSON Datatype
Papers We Love Kyiv, July 2018: A Conflict-Free Replicated JSON Datatype
 
KharkivJS 2017: Коллаборативные системы и CRDT
KharkivJS 2017: Коллаборативные системы и CRDTKharkivJS 2017: Коллаборативные системы и CRDT
KharkivJS 2017: Коллаборативные системы и CRDT
 
OdessaJS 2017: Groupware Systems for fun and profit
OdessaJS 2017: Groupware Systems for fun and profitOdessaJS 2017: Groupware Systems for fun and profit
OdessaJS 2017: Groupware Systems for fun and profit
 
PyCon Ukraine 2017: Operational Transformation
PyCon Ukraine 2017: Operational Transformation PyCon Ukraine 2017: Operational Transformation
PyCon Ukraine 2017: Operational Transformation
 
Communicating Sequential Processes (CSP) in JavaScript
Communicating Sequential Processes (CSP) in JavaScriptCommunicating Sequential Processes (CSP) in JavaScript
Communicating Sequential Processes (CSP) in JavaScript
 
PiterPy 2016: Parallelization, Aggregation and Validation of API in Python
PiterPy 2016: Parallelization, Aggregation and Validation of API in PythonPiterPy 2016: Parallelization, Aggregation and Validation of API in Python
PiterPy 2016: Parallelization, Aggregation and Validation of API in Python
 
Fighting async JavaScript (CSP)
Fighting async JavaScript (CSP)Fighting async JavaScript (CSP)
Fighting async JavaScript (CSP)
 
React.js: Ускоряем UX/UI
React.js: Ускоряем UX/UIReact.js: Ускоряем UX/UI
React.js: Ускоряем UX/UI
 
KharkovPy #12: I/O in Python apps and smart logging (russian)
KharkovPy #12: I/O in Python apps and smart logging (russian)KharkovPy #12: I/O in Python apps and smart logging (russian)
KharkovPy #12: I/O in Python apps and smart logging (russian)
 
5 мифов о производительности баз данных и Python
5 мифов о производительности баз данных и Python5 мифов о производительности баз данных и Python
5 мифов о производительности баз данных и Python
 
Изоформные приложения на React.js
Изоформные приложения на React.jsИзоформные приложения на React.js
Изоформные приложения на React.js
 
Изоморфный JavaScript (iForum 2015)
Изоморфный JavaScript (iForum 2015)Изоморфный JavaScript (iForum 2015)
Изоморфный JavaScript (iForum 2015)
 
Трансдюсеры, CSP каналы, неизменяемые структуры данных в JavaScript
Трансдюсеры, CSP каналы, неизменяемые структуры данных в JavaScriptТрансдюсеры, CSP каналы, неизменяемые структуры данных в JavaScript
Трансдюсеры, CSP каналы, неизменяемые структуры данных в JavaScript
 
PiterPy 2015 - Трансдюсеры и Python
PiterPy 2015 - Трансдюсеры и PythonPiterPy 2015 - Трансдюсеры и Python
PiterPy 2015 - Трансдюсеры и Python
 
Robust web apps with React.js
Robust web apps with React.jsRobust web apps with React.js
Robust web apps with React.js
 
LvivJS 2014 - Win-win c React.js
LvivJS 2014 - Win-win c React.jsLvivJS 2014 - Win-win c React.js
LvivJS 2014 - Win-win c React.js
 
Инновации и JavaScript
Инновации и JavaScriptИнновации и JavaScript
Инновации и JavaScript
 
Odessapy2013 - Graph databases and Python
Odessapy2013 - Graph databases and PythonOdessapy2013 - Graph databases and Python
Odessapy2013 - Graph databases and Python
 
Angular.js - JS Camp UKraine 2013
Angular.js - JS Camp UKraine 2013Angular.js - JS Camp UKraine 2013
Angular.js - JS Camp UKraine 2013
 
Зачем читать чужой код?
Зачем читать чужой код?Зачем читать чужой код?
Зачем читать чужой код?
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

Kharkivpy#3: Javascript and Python backend

  • 1. JavaScript and Python back-end Max Klymyshyn oDesk PS Twitter: @maxmaxmaxmax Github: joymax Sources: goo.gl/zbtXH Saturday, March 24, 12 1
  • 2. The problem JavaScript code grew up on the Project Optimization of the Application become the pain in the ass Hard to manage dependencies and test updates Saturday, March 24, 12 2
  • 3. The solution Add Assets Management tools to the project Define and follow conventions Saturday, March 24, 12 3
  • 4. TOC Project Structure Assets management JavaScript Templates Constants within JS files Browser-specific assets SCSS/LESS Saturday, March 24, 12 4
  • 5. Note This presentation based on Flask but it's possible to use Django or any other framework which supported by Webassets Saturday, March 24, 12 5
  • 6. Project structure • app.py • assets.py • templates • base.html • bundles • browsers.py • jstemplates.py • scss_bundle.py • vars.py • static • src • js • css • js • css Saturday, March 24, 12 6
  • 7. Assets management core = Bundle( "src/js/lib/core/*.js", "src/js/lib/*.js", output="core.js" ) assets.register("js_core", core) Saturday, March 24, 12 7
  • 8. JavaScript Templates var %(namespace)s = %(namespace)s || {}; %(namespace)s._assign = function (obj, keyPath, value) { var lastKeyIndex = keyPath.length - 1; for (var i = 0; i < lastKeyIndex; i++) { key = keyPath[i]; if (typeof obj[key] === "undefined") { obj[key] = {}; } obj = obj[key]; } obj[keyPath[lastKeyIndex]] = value; }; (function(){ // ... here should be templates definitions })(); Saturday, March 24, 12 8
  • 9. JavaScript templates templates = ( 'system/*.tpl', 'views/main/*.tpl', 'views/group/*.tpl', 'views/rate/*.tpl', 'views/search/*.tpl', 'views/sort/*.tpl', 'views/progress/*.tpl', 'views/sidebar/listings/*.tpl', 'views/sidebar/search/*.tpl', ) Saturday, March 24, 12 9
  • 10. Constants within JavaScript def constants(app): cfg = {} with app.test_request_context(): cfg.update(dict( API_URL=url_for("api", _external=True), TITLE="Sample Widget" )) return cfg conf_app = JSVarsBundle("src/js/conf/main.js", output="js/compiled/conf/conf.js", vars=constants(app), filters=[“yui_js”], ignore_filters=assets.debug ) Saturday, March 24, 12 10
  • 11. Constants within JavaScript Configuration file looks like: ... _.defaults(config, { 'api_url': '$$API_URL', 'title': '$$TITLE' }); window.KHARKIVPY.config = config; Saturday, March 24, 12 11
  • 12. Browser-specific assets We need to load custom assets for different browsers We don’t have ability to use conditional commends for IEs (business requirement) Saturday, March 24, 12 12
  • 13. Browser-specific assets chrome17 = BrowserBundle( 'src/css/browsers/chrome17.css', browser='Chrome', browser_version='17', output='css/chrome17.css' ) ... browserspec_assets_loader = LoaderBrowserBundle( 'src/css/browsers/safari5.css', # dirty hack, we’ll change it bundles=[chrome17, safari5], filters='loader_browser', output='js/compiled/assets-loader.js' ) assets.register( "browserspec_assets_loader", browserspec_assets_loader) Saturday, March 24, 12 13
  • 14. Browser-specific assets Below is generated snippet by webassets bundle: (function (assets) { BrowserAssets('/static/', assets); })({ 'Chrome': { '17': ['src/css/browsers/chrome17.css']}, 'Safari': { '5.1': ['src/css/browsers/safari5.css']} }); Saturday, March 24, 12 14
  • 15. SCSS/LESS It was painful to maintain raw CSS for complex public widget We declined to use LESS because we aren’t found good and maintainable LESS compiler for Python We decided to not use client-side LESS parser to avoid possible conflicts with client’s code Saturday, March 24, 12 15
  • 16. SCSS/LESS style_files = ( 'reset.scss', 'base.scss', ) register_scss_bundle( style_files, assets=assets, name='css_core', output='css/style.css', prefix='src/css', compile_to='css/compiled' ) Saturday, March 24, 12 16
  • 17. CDN (Amazon CloudFront) Sometimes back-end server goes down Clients and partners may experience really weird behavior and look of the Widget when back-end not available No one want to loose face in front of the client Saturday, March 24, 12 17
  • 18. CDN (Amazon CloudFront) All of static related to the Widget hosted on Amazon CloudFront In case back-end goes down for maintenance or because of failure JavaScript display nice error Widget still looks like it should Saturday, March 24, 12 18
  • 19. CDN Pitfalls Amazon CloudFront may update your files REALLY SLOW It may take up to 24 hrs to spread updates to all CDN nodes around the world You may experience hard time with your product owner CDN is for really patient clients Saturday, March 24, 12 19