A presentation at GDG Craiova DevFest in in Craiova, Romania by Matthieu Auger
Near Instant Load Times at Scale with GatsbyJS
PERFORMANCE MATTERS
Zalando saw a 0.7% increase in revenue when they shaved 100ms off their load time. Trainline reduced latency by 0.3 seconds across their funnel and customers spent an extra £8 million (~€9.1 million) a year. BBC has seen that they lose an additional 10% of users for every additional second it takes for their site to load Rebuilding Pinterest pages for performance resulted in a 15% increase in SEO traffic and a 15% increase in conversion rate to signup.
“Poor performance can, and does, lead to exclusion.” — Tim Kadlek
Source: https://v8.dev/blog/cost-of-javascript-2019
Source: https://blog.chriszacharias.com/page-weight-matters
In 2009, YouTube engineer Chris Zacharias tackled the page weight of youtube.com and reduced it from 1.2MB to less than 100KB. “He pushed the feature in production, waited for the results of how much he’d have improved the performance. After a week of data collection, the numbers came back… and they were baffling. The average aggregate page latency under the new version had actually INCREASED.” “Under the new version, despite it taking over two minutes to get to the first frame of video, watching a video actually became a real possibility [in developing countries]. […] Large numbers of people who were previously unable to use YouTube were suddenly able to.”
“[Performance good practices] have well-known benefits to usability, but are also acts of environmental protection.” — Cennydd Bowles, Future Ethics
🐌 “I need to buy a new phone” 🔋 “My battery does not last a full day anymore” Source: https://timkadlec.com/remembers/2019-01-09-the-ethics-of-performance/
New devices hide performance issues on our websites Pushing users to buy new devices Reducing the perceived need to work on performance Making sites slower on old devices
$ Numele meu este Matthieu VP of Engineering at Theodo 🥇#1 time in Romania - 🎨 Colorblind @matthieuauger
Angular, React, Vue… 📺 HTML is computed client-side 🖱Interactiveness
🐘 PHP, Python, Ruby 💻 HTML is computed server-side Dynamic
Pure HTML files served by server 🥇 First ever page on the Web ⚡ Simple. Scalable. Fast
You code in React . Application is compiled to HTML at build time
Can I have the homepage please? yeah, take this HTML file, a snapshot of the page I made during the build sweet! i can see the content first… React environment is loaded client-side and now click around! Following navigation is managed by React
My colleague Nicolas
“a modern web development architecture based on client-side JavaScript, reusable APIs, and prebuilt Markup.”
Displays meet-ups from meetup.com API 📸 Picture gallery ⚡ Performance
1 Pull Data from sources . Query Data with GraphQL 2 Pass data to React Components
gatsby-config.js module.exports = ({ … plugins: [ { resolve: gatsby-source-meetup
, options: { key: process.env.MEETUP_API_KEY, groupUrlName: JAMstack-paris, status: “upcoming,past”, desc: “true”, page: 10 } } ] });
FETCHING DATA ON MEETUP API
Query Language 💙 Created by Facebook 🥢 Request only data you want 👯 Same interface for all your data sources
Homepage.js
const data = useStaticQuery( graphqlquery { meetupGroup { events { id name description local_date venue { name address_1 city } link status } name } }
);
Homepage.js return ( <Layout> {data.meetupGroup.events.map(pastMeetup => { return <Meetup meetupInfo={pastMeetup} /> })} </Layout> )
Look for, install and configure related source plugin ⚙ . Get your GraphQL right with GraphiQL 9 2 Inject it to your React components 💉
; How to serve high quality images to high resolution devices? ; How to optimise image size of small devices? ; How not to wait for full download of images before rendering the pages?
gatsby-config.js module.exports = { plugins: [ { resolve: gatsby-source-filesystem
, options: { name: gallery
, path: ${__dirname}/src/images/gallery
} } ] };
SPECIFY WIDTH AND HEIGHT
GENERATES HIGHRES VERSIONS <picture><source srcset=” /static/762d4c85dbed42f294dd8870c0200bc6/792e8/meetup-lbc-haroen.jpg 1x, /static/762d4c85dbed42f294dd8870c0200bc6/c3f37/meetup-lbc-haroen.jpg 1.5x, /static/762d4c85dbed42f294dd8870c0200bc6/1eaf9/meetup-lbc-haroen.jpg 2x “/> <img srcset=” /static/762d4c85dbed42f294dd8870c0200bc6/792e8/meetup-lbc-haroen.jpg 1x, /static/762d4c85dbed42f294dd8870c0200bc6/c3f37/meetup-lbc-haroen.jpg 1.5x, /static/762d4c85dbed42f294dd8870c0200bc6/1eaf9/meetup-lbc-haroen.jpg 2x ” src=”/static/762d4c85dbed42f294dd8870c0200bc6/792e8/meetup-lbc-haroen.jpg” alt=”JAMstack Paris Gallery Picture” width=”300” height=”300” loading=”lazy” style=”position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; objectfit: cover; object-position: center center; opacity: 1; transition: opacity 500ms ease 0s;” /></picture>
✅ How to serve high quality images to high resolution devices? ✅ How to optimise image size of small devices? ; How not to wait for full download of images before rendering the pages?
TRACED SVG?
“I designed Gatsby with the goal that when using it, it’d be really hard to build a slow site” — Kyle Matthews, GatsbyJS creator
Goal of code splitting: only bring to the user what he needs, when he needs it. We will split our Javascript in multiple chunks and when the user makes an action, he will only receive the related Javascript
Homepage JS Gallery JS GATSBY-IMAGE IS ONLY LOADED ON GALLERY
🖱Native Lazy Loading 🎨 Inline Critical CSS . HTTP2
“builds are slow (about 1.5-2 times slower than my PC) and […] 15 minutes is sometimes easy to reach” Source: https://oioannou.com/build-on-circleci-deploy-netlify
😍 Really good experience 📓 Documentation is great 👫 Community is positive and helpful ❤ The hybrid approach of static and dynamic 🏰 Still look for a professional project to use Gatsby with
📒 https://www.gatsbyjs.org/docs/ 📹 https://egghead.io/browse/frameworks/gatsby https://github.com/gatsbyjs/gatsby
“share design, components and set of plugins easily still allowing configuration and overriding”
https://github.com/matthieuauger/ gatsby-theme-meetup
Follow this guy, he tweets about Web Performance: phacks
GatsbyJS is a library that adds powerful static capabilities to React-powered webapps and packs many performance optimizations, making websites load instantly, by default.
Gatsby plugins allows any datasource, including custom APIs, into a Gatsby-powered website with the expressiveness of GraphQL.
In this talk we will cover the following topics:
By the end of the talk, the audience will understand why GatsbyJS may be the next game-changer in terms of performance & DX and when to start with (or migrate over to) GatsbyJS.