Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Ditching the Single Page Application - Madison+...
Search
Starr Horne
September 01, 2015
270
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Ditching the Single Page Application - Madison+Ruby 2015
Starr Horne
September 01, 2015
More Decks by Starr Horne
See All by Starr Horne
Ditching the Single Page Application (RubyNation 2015)
snhorne
1
280
SVG Charts and Graphs With Ruby
snhorne
0
240
SVG Charts and Graphs With Ruby
snhorne
0
400
The short but happy lives of TCP and HTTP requests
snhorne
4
410
Machine Learning Techniques You Can Use Today
snhorne
4
220
Biggish Data with Rails and Postgresql
snhorne
3
990
Featured
See All Featured
BBQ
matthewcrist
89
10k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
650
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
200
Why Our Code Smells
bkeepers
PRO
340
58k
Site-Speed That Sticks
csswizardry
13
1.3k
WENDY [Excerpt]
tessaabrams
11
38k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.5k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
930
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.7k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.8k
Chasing Engaging Ingredients in Design
codingconduct
0
230
Into the Great Unknown - MozCon
thekraken
41
2.6k
Transcript
Ditching the Single Page Applica0on
by Starr Horne And me! Evil Starr!
Ditching the Single Page Applica0on
by Starr Horne And me! Evil Starr!
StarrHorne
StarrHorne
StarrHorne
StarrHorne
StarrHorne
StarrHorne
StarrHorne Tradi0onal app: Every page is a new
HTTP request
StarrHorne Single page app: All data retrieved by
Ajax and rendered client side
StarrHorne PJAX/Turbolinks: Best of both worlds? BOO! Turbolinks
Sucks! I tried it one morning
StarrHorne
StarrHorne
StarrHorne Spin the boFle-‐neck
StarrHorne
StarrHorne
StarrHorne It’s 4, dummy!
StarrHorne
StarrHorne Single-‐page apps can provide the illusion of speed
StarrHorne Oh, snap. We didn’t really merge that
PR x
StarrHorne Some bo@lenecks can’t be avoided by tricks
StarrHorne Queries take 0me to run
StarrHorne Data processing also takes 0me even when offloaded
to the client
StarrHorne ?
StarrHorne We knew all these things but we sNll
chose an SPA architecture, originally
StarrHorne Over the years that followed, our app became
Curiouser and Curiouser
StarrHorne Did we just build a browser …inside
the browser?
StarrHorne Has anyone seen the UI? I think It’s
under all these modals.
StarrHorne So I’ll just add a count_since_thursday field
to the API
StarrHorne Let’s go compile some assets, friend
StarrHorne Twi3er is SCIENCE!
StarrHorne What if nobody had to write JS on
a daily basis?
StarrHorne Array + Object == String …Makes sense
StarrHorne
StarrHorne
StarrHorne So we ditched our single-‐page app and rebuilt.
This 0me with PJAX.
StarrHorne https://ntotten.com/2012/04/09/building-super-fast-web-apps-with-pjax/ PJAX combines server-‐rendered HTML with Javascript magic.
StarrHorne An unassuming web page …li@le did they know
the secrets that lurked within
StarrHorne
StarrHorne
StarrHorne
StarrHorne PJAX solves the page reload boFleneck …just like
a single-‐page app
StarrHorne PJAX lets you do clever tricks to create
the percep0on of speed
StarrHorne PJAX puts your rendering and logic back in Ruby
…just like old 0mes
StarrHorne What a terrible commit message! PJAX lets you delete
all that Javascript. It speeds both compila0on & page load
StarrHorne With PJAX you ship faster
StarrHorne Well, How do I work this? How do
I get there?
StarrHorne This library is pre@y good hFps:/ /github.com/defunkt/jquery-‐pjax
StarrHorne Front End
StarrHorne Back End
StarrHorne There’s another PJAX library It kind of pissed
people off
StarrHorne
StarrHorne Wri0ng JS for pages that never reload is
a different beast
StarrHorne It’s easy to set traps for yourself without
even realizing it
StarrHorne Every un-‐scoped selector is like a dependency
on a global variable
StarrHorne
StarrHorne
StarrHorne It’s helpful to think in terms of components
No maFer what component system you use
StarrHorne This is one way to scope a selector
StarrHorne By commiYng to one “global variable” you save
three
StarrHorne
StarrHorne ] Scope JS to HTML 0ghtly This is
the secret
StarrHorne
StarrHorne
StarrHorne Use a naming conven0on for your components That
way you know what they are
StarrHorne
StarrHorne Ini0alize components when the container is detected Don’t
iniNalize them manually
StarrHorne
StarrHorne When you master these things you will eliminate
conflict from your Javascript
StarrHorne You had the power all along
StarrHorne Want more details & fewer hand waves? There’s
a blog post coming. @StarrHorne