Skip to content

Commit 49f25ce

Browse files
committed
feat: support Netlify Image CDN
1 parent aad8712 commit 49f25ce

File tree

17 files changed

+271
-1908
lines changed

17 files changed

+271
-1908
lines changed

README.md

+16-55
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,7 @@ commands separately will not work, because the Next.js Runtime will not generate
1414
## Using `next/image`
1515

1616
If you use [`next/image`](https://nextjs.org/docs/basic-features/image-optimization), your images will be automatically
17-
optimized at runtime, ensuring that they are served at the best size and format. The image will be processed on the
18-
first request which means it may take longer to load, but the generated image is then cached and served as a static file
19-
to future visitors. By default, Next.js will deliver WebP images if the browser supports it. WebP is a modern image format
20-
with wide browser support that will usually generate smaller files than PNG or JPG. Additionally, you can enable AVIF
21-
format, which is often even smaller in filesize than WebP. The drawback is that with particularly large images, AVIF images may
22-
take too long to generate, and the function times-out. You can configure
23-
[the supported image formats](https://nextjs.org/docs/api-reference/next/image#acceptable-formats) in your
24-
`next.config.js` file.
25-
26-
### Enabling Edge Images
27-
28-
It is possible to run image content negotiation on the edge. This allows images to be processed on the first request,
29-
and then, in future loads, served from cache on the edge.
30-
31-
In order to deliver the correct format to a visitor's browser, this uses a Netlify Edge Function. In some cases your
32-
site may not support Edge Functions, in which case it will instead fall back to delivering the original file format.
33-
34-
To turn on Edge image handling for Next/Image, set the environment variable `NEXT_FORCE_EDGE_IMAGES` to `true`
35-
36-
## Returning custom response headers on images handled by `ipx`
37-
38-
Should you wish to return custom response headers on images handled by the
39-
[`netlify-ipx`](https://github.com/netlify/netlify-ipx) package, you can add them within your project's `netlify.toml`
40-
by targeting the `/_next/image/*` route:
41-
42-
```
43-
[[headers]]
44-
for = "/_next/image/*"
45-
46-
[headers.values]
47-
Strict-Transport-Security = "max-age=31536000"
48-
X-Test = 'foobar'
49-
```
50-
51-
## Disabling included image loader
52-
53-
If you wish to disable the use of the image loader which is bundled into the runtime by default, set the `DISABLE_IPX`
54-
environment variable to `true`.
55-
56-
This should only be done if the site is not using `next/image` or is using a different loader (such as Cloudinary or
57-
Imgix).
58-
59-
See the [Next.js documentation](https://nextjs.org/docs/api-reference/next/image#built-in-loaders) for image loader
60-
options.
17+
optimized at runtime using the Netlify Image CDN.
6118

6219
## Next.js Middleware on Netlify
6320

@@ -91,7 +48,10 @@ Note that Netlify has a minimum TTL of 60 seconds for revalidation.
9148

9249
## Disable Static 404 on Dynamic Routes with fallback:false
9350

94-
Currently when hitting a non-prerendered path with `fallback=false` it will default to a 404 page. You can now change this default setting by using the environemnt variable `LEGACY_FALLBACK_FALSE=true`. With the environment variable set, those non-prerendered paths will now be routed through using the ISR Handler and will allow you to add redirects for those non-prerendered paths.
51+
Currently when hitting a non-prerendered path with `fallback=false` it will default to a 404 page. You can now change
52+
this default setting by using the environemnt variable `LEGACY_FALLBACK_FALSE=true`. With the environment variable set,
53+
those non-prerendered paths will now be routed through using the ISR Handler and will allow you to add redirects for
54+
those non-prerendered paths.
9555

9656
## Use with `next export`
9757

@@ -111,14 +71,12 @@ that it is not enabled at **Site settings > Build & deploy > Post processing > A
11171
## Generated functions
11272

11373
The Next.js Runtime works by generating three Netlify functions that handle requests that haven't been pre-rendered.
114-
These are `___netlify-handler` (for SSR and API routes), `___netlify-odb-handler` (for ISR and fallback routes), and
115-
`_ipx` (for images). You can see the requests for these in
116-
[the function logs](https://docs.netlify.com/functions/logs/). For ISR and fallback routes you will not see any requests
117-
that are served from the edge cache, just actual rendering requests. These are all internal functions, so you won't find
118-
them in your site's own functions directory.
74+
These are `___netlify-handler` (for SSR and API routes) and `___netlify-odb-handler` (for ISR and fallback routes). You
75+
can see the requests for these in [the function logs](https://docs.netlify.com/functions/logs/). For ISR and fallback
76+
routes you will not see any requests that are served from the edge cache, just actual rendering requests. These are all
77+
internal functions, so you won't find them in your site's own functions directory.
11978

120-
The Next.js Runtime will also generate a Netlify Edge Function called 'ipx' to handle image content negotiation, and if
121-
Edge runtime or middleware is enabled it will also generate edge functions for middleware and edge routes.
79+
If Edge runtime or middleware is enabled it will also generate edge functions for middleware and edge routes.
12280

12381
## Manually installing the Next.js Runtime
12482

@@ -190,13 +148,15 @@ npm test
190148

191149
### End-to-end tests
192150

193-
In order to run the end-to-end (E2E) tests, you'll need to be logged in to Netlify. You can do this using the [Netlify CLI](https://github.com/netlify/cli) with the command:
151+
In order to run the end-to-end (E2E) tests, you'll need to be logged in to Netlify. You can do this using the
152+
[Netlify CLI](https://github.com/netlify/cli) with the command:
194153

195154
```shell
196155
netlify login
197156
```
198157

199-
Alternatively, you can set an environment variable `NETLIFY_AUTH_TOKEN` to a valid Netlify personal access token. This can be obtained from the [Netlify UI](https://docs.netlify.com/cli/get-started/#obtain-a-token-in-the-netlify-ui).
158+
Alternatively, you can set an environment variable `NETLIFY_AUTH_TOKEN` to a valid Netlify personal access token. This
159+
can be obtained from the [Netlify UI](https://docs.netlify.com/cli/get-started/#obtain-a-token-in-the-netlify-ui).
200160

201161
Then run the E2E tests if logged in:
202162

@@ -210,7 +170,8 @@ Or if using an access token:
210170
NETLIFY_AUTH_TOKEN=your-token-here npm run test:next
211171
```
212172

213-
_Note: The E2E tests will be deployed to a Netlify owned site. To deploy to your own site then set the environment variable `NETLIFY_SITE_ID` to your site ID._
173+
_Note: The E2E tests will be deployed to a Netlify owned site. To deploy to your own site then set the environment
174+
variable `NETLIFY_SITE_ID` to your site ID._
214175

215176
## Feedback
216177

demos/default/netlify.toml

-7
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ NODE_VERSION = "16.15.1"
1313
NEXT_SPLIT_API_ROUTES = "true"
1414
NEXT_BUNDLE_BASED_ON_NFT_FILES = "true"
1515

16-
[[headers]]
17-
for = "/_next/image/*"
18-
19-
[headers.values]
20-
Strict-Transport-Security = "max-age=31536000"
21-
X-Test = 'foobar'
22-
2316
[[plugins]]
2417
package = "@netlify/plugin-nextjs"
2518

0 commit comments

Comments
 (0)