Skip to content

Commit 67894ad

Browse files
committed
Add Ship Public Assets With A Next.js App as a next.js til
1 parent ac00a23 commit 67894ad

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010

1111
For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud).
1212

13-
_1107 TILs and counting..._
13+
_1108 TILs and counting..._
1414

1515
---
1616

@@ -490,6 +490,7 @@ _1107 TILs and counting..._
490490
- [Create Files And Directories For Dynamic Routes](nextjs/create-files-and-directories-for-dynamic-routes.md)
491491
- [Define URL Redirects In The Next Config](nextjs/define-url-redirects-in-the-next-config.md)
492492
- [Remove A Query Param From The URL](nextjs/remove-a-query-param-from-the-url.md)
493+
- [Ship Public Assets With A Next.js App](nextjs/ship-public-assets-with-a-nextjs-app.md)
493494

494495
### Phoenix
495496

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Ship Public Assets With A Next.js App
2+
3+
A Next.js project includes a top-level `public` directory. Anything in this
4+
directory at build time will be publicly available.
5+
6+
This is handy for things like a logo, cover image, or favicon.
7+
8+
If I create an `images` directory in `public` and then place an SVG in it:
9+
10+
```bash
11+
$ ls public/images
12+
logo.svg
13+
```
14+
15+
Then I can reference that image in the HTML or JSX of my app pages, such as in
16+
a `header.jsx` component.
17+
18+
```jsx
19+
const Header = () => {
20+
<div>
21+
{/* a bunch of header and nav content */}
22+
<img className="logo" src="/images/logo.svg" />
23+
</div>
24+
}
25+
```
26+
27+
Notice it is publicly available at `/images/logo.svg`.
28+
29+
You can do this with other files as well. For instance, some kind of company
30+
brochure PDF could be placed in `public` and you could link to it as a
31+
download.
32+
33+
[source](https://nextjs.org/docs/basic-features/static-file-serving)

0 commit comments

Comments
 (0)