Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Incredibly fast web apps

Incredibly fast web apps

Get your web app extremely fast by optimizing it outside of the app itself. If done right, it’s possible to reduce your loading times to less than 50 ms by using a CDN in front of your app, moving some kind of code into JavaScript, setting the right headers, and using localStorage.

I gave this talk at RubyConf Philippines (http://rubyconf.ph) and RUG-B (http://www.rug-b.de).

Video recording: https://www.youtube.com/watch?v=V7ul3yIhz4o&index=8&list=PL0mVjsUoElSHRZWXz3VPo0vRUm75hNP7j

Follow me on Twitter for updates about speed, Ruby, design, CSS and Sass as well as living style guides: https://twitter.com/hagenburger

Nico Hagenburger

April 07, 2016
Tweet

More Decks by Nico Hagenburger

Other Decks in Programming

Transcript

  1. FRE E LA NC E DE V E LO P

    ER /D ES IG N ER Front-end developer designer Ruby lover
  2. Don’t just focus on cached assets ★ Cache everything (at

    least for a while) ★ Act like you have a static good old HTML page like it’s 1999
  3. Downsides −Do you know how to do it? −Do you

    want to maintain it? −Is it close to your customers?
  4. CDN providers +They know what they do +They have several

    servers +They might deliver from many locations −They can get expensive −You might hit their limits easily
  5. CDN locations ★ Just Europe and North America? ★ “The

    whole world”? ★ In or outside the Great Firewall? ★ Including the Philippines? ★ Akamai and MetaCDN seem to http://www.metacdn.com/cdn-coverage http://www.mb.com.ph/pldt-partners-with-akamai-for-content-delivery-network-solutions/
  6. Cache synching ★ Do all servers world wide need to

    request the page from your server? ★ Or do they share their cache?
  7. Purge requests ★ CloudFlare has strict API limits ★ Pages

    won’t get purged after you hit them ★ CloudFront charges per purge request ★ Can get pretty expensive ★ CloudFlare purges within 30 sec, 
 CloudFront might take 30 min
  8. Log in/out ★ Just switch the CSS class ★ No

    need to reload the page free Bonus!
  9. Look at slow queries ★ Watch your logs ★ Use

    indexes ★ Cache calculated values (e.g.: a score) ★ Experiment with queries
  10. Remote partials ★ Cache the main HTML page (e.g. an

    article) ★ Load dynamic content separately: ★ Recommended articles ★ Comments ★ Global elements ★ Page and partials can have different caching strategies
  11. Don’t check for a session ★ Skip before actions etc.

    ★ Most cached pages do not rely on a session ★ Some uncached requests just don’t need it
  12. Asset hashes ★ /assets/my-a24d3.css ★ Will remain in cached HTML

    pages ➤ Requires purging the whole cache ★ Possible solution: Use redirects ➤ /a/assets/my.css > /assets/my- a24d3.css
  13. No Coffee-Script 
 in views ★ Do you really want

    to compile this with each request?
  14. Avoid too many URLs ★ /photos vs. /photos/ ★ /photos

    vs. /photos?size=m ★ /photos vs. /photos?utm_campaign=…&… ★ /photos?size=m&page=2 vs.
 /photos?page=2&size=m
  15. CSRF token ★ Don’t include in the HTML on cached

    pages ★ (I should test all this in Rails 5)
  16. Within Ruby* ★ Cache results/partials ★ Sometimes avoid blocks in

    HTML ★ Prefer ERB over Haml/Slim/… ★ Skip unused code * from a front-end coder’s perspective
  17. Caching ★ Cache everything possible ★ Choose a CDN matching

    your requirements ★ Load dynamic parts via XHR ★ Be aware uncached requests remain slow ★ Set the right headers for the browser
  18. JavaScript ★ Don’t use Coffee-Script in views ★ Use Vanilla.js

    if possible ★ Use it for session handling and displaying content ★ Be aware of Safari’s private mode!
  19. [email protected] email twitter blog first name last name Salamat &

    thank you! I’M NOT HIRING. BUT TALK TO ME IF YOU WANT TO WORK WITH ME ON SOMETHING.