Follow me on Twitter for updates about speed, Ruby, design, CSS and Sass as well as living style guides: https://twitter.com/hagenburger
WITHOUT TOUCHING RUBY (TOO MUCH)
ORGA NI Z ER / DE SIG NE R
OP E N -S OURCE DE VE LO PE R
FRE E LA NC E DE V E LO P ER /D ES IG N ER
I heard Ruby is slow.
Might not be true.
Thank you for all the
Thank you so much!
But let’s have a look
on how to improve
Which part of our
actually is slow?
(rather your queries)
The Great Firewall?
Just use ERB.
Everything else is slower.
(Except helpers written in pure Ruby maybe)
Put layout CSS
into the HTML
… and load the CSS
step by step
Set image sizes
Set CSS width/height
Loading jQuery via
★ Yes, it’s faster.
★ But in China:
Don’t just focus on
★ Cache everything (at least for a while)
★ Act like you have a static good old HTML
page like it’s 1999
Rails page caching
★ More than one server?
★ More than one domain?
★ Uses the same server
−Do you know how to do it?
−Do you want to maintain it?
−Is it close to your customers?
Use a content
as a service
+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
Be close to
★ Just Europe and North America?
★ “The whole world”?
★ In or outside the Great Firewall?
★ Including the Philippines?
★ Akamai and MetaCDN seem to
★ Do all servers world wide need to request
the page from your server?
★ Or do they share their cache?
★ Clears the cache at the CDN for a specific
★ CloudFlare has strict API limits
★ Pages won’t get purged after you hit
★ CloudFront charges per purge request
★ Can get pretty expensive
★ CloudFlare purges within 30 sec,
CloudFront might take 30 min
CDNs don’t know
about your user
Any page containing
is hard to cache
This is a lot of work.
– Logged in content
– Logged out content
Don’t show things,
hide the others.
The opposite of
★ Just switch the CSS class
★ No need to reload the page
Look at slow queries
★ Watch your logs
★ Use indexes
★ Cache calculated values (e.g.: a score)
★ Experiment with queries
Use remote partials
★ Cache the main HTML page (e.g. an article)
★ Load dynamic content separately:
★ Recommended articles
★ Global elements
★ Page and partials can have different
Don’t check for a
★ Skip before actions etc.
★ Most cached pages do not rely on a
★ Some uncached requests just don’t need it
★ Will remain in cached HTML pages
➤ Requires purging the whole cache
★ Possible solution: Use redirects
➤ /a/assets/my.css > /assets/my-
★ Sometimes plain HTML is faster
★ Especially in blocks
★ Rails has a cache helper. Use it.
★ Do you really want to compile this with
Avoid too many URLs
★ /photos vs. /photos/
★ /photos vs. /photos?size=m
★ /photos vs. /photos?utm_campaign=…&…
★ /photos?size=m&page=2 vs.
★ Don’t include in the HTML on cached
★ (I should test all this in Rails 5)
★ Cache results/partials
★ Sometimes avoid blocks in HTML
★ Prefer ERB over Haml/Slim/…
★ Skip unused code
* from a front-end coder’s perspective
★ Cache everything possible
★ Choose a CDN matching your
★ Load dynamic parts via XHR
★ Be aware uncached requests remain slow
★ Set the right headers for the browser
★ Don’t use Coffee-Script in views
★ Use Vanilla.js if possible
★ Use it for session handling and displaying
★ Be aware of Safari’s private mode!
★ Build a MVP
★ Less features, more speed :)
all you can do.
It’s just a good start.
Only speed up
As fast as Ruby
will get—not calling
Ruby at all will always
Salamat & thank you!
I’M NOT HIRING. BUT TALK TO ME IF YOU WANT TO WORK WITH ME ON SOMETHING.