Skip to Content
Gatsby: The Definitive Guide
book

Gatsby: The Definitive Guide

by Preston So
September 2021
Intermediate to advanced
539 pages
12h 41m
English
O'Reilly Media, Inc.
Content preview from Gatsby: The Definitive Guide

Chapter 7. Assets in Gatsby

While creating and generating pages is one of the aspects of Gatsby that receives the most attention, Gatsby’s asset handling capabilities are also highly robust. After all, when building Gatsby sites, it’s not just text we’re concerned with; often, as developers, we must also juggle images, videos, fonts, and other file assets that don’t fit neatly into our sites. Complicating matters further is the fact that today’s users demand highly performant and optimized image and video delivery.

There are a variety of plugins and APIs available to interact with different assets you might want to include in your Gatsby site, be they photographs, video streams, web fonts, or PDF documents. We’ll look at the best practices Gatsby offers for specific asset types (images, videos, and fonts), but we’ll begin with an overview of how to work with assets in general in Gatsby: by importing them into Webpack as part of the module system or importing them on their own as static assets.

Working with Assets

In Gatsby, an asset is loosely defined as any file that needs to be used anywhere in a Gatsby site, whether that means in a Gatsby page, a React component, or a Markdown file. Assets can run the gamut from images in JPEG and PNG formats to animated GIFs as well as videos, fonts, and other static files with arbitrary extensions.

Types of Assets in Gatsby

Before we get into the two approaches for importing assets, let’s briefly examine which types of assets (which Gatsby ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Foundation Gatsby Projects: Create Four Real Production Websites with Gatsby

Foundation Gatsby Projects: Create Four Real Production Websites with Gatsby

Nabendu Biswas
The Jamstack Book

The Jamstack Book

Raymond K. Camden, Brian Rinaldi

Publisher Resources

ISBN: 9781492087502Errata Page