From Event to Action: Accelerate Your Decision Making with Real-Time Automation
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
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
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
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