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
0
250
Ditching the Single Page Application - Madison+Ruby 2015
Starr Horne
September 01, 2015
Tweet
Share
More Decks by Starr Horne
See All by Starr Horne
Ditching the Single Page Application (RubyNation 2015)
snhorne
1
240
SVG Charts and Graphs With Ruby
snhorne
0
170
SVG Charts and Graphs With Ruby
snhorne
0
360
The short but happy lives of TCP and HTTP requests
snhorne
4
380
Machine Learning Techniques You Can Use Today
snhorne
4
190
Biggish Data with Rails and Postgresql
snhorne
3
940
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
169
14k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
Designing the Hi-DPI Web
ddemaree
280
34k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
A designer walks into a library…
pauljervisheath
204
24k
Into the Great Unknown - MozCon
thekraken
32
1.5k
Making Projects Easy
brettharned
115
5.9k
Navigating Team Friction
lara
183
14k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
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