Skip to content

Commit

Permalink
Merge pull request #1 from klavavej/patch-1
Browse files Browse the repository at this point in the history
Docs for Netlify Image CDN implementation
  • Loading branch information
ascorbic authored Feb 9, 2024
2 parents 5f67712 + 573e42e commit ce84424
Showing 1 changed file with 59 additions and 8 deletions.
67 changes: 59 additions & 8 deletions docs/content/3.providers/netlify.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,72 @@ links:
size: xs
---

When deploying your Nuxt applications to [Netlify's composable platform](https://docs.netlify.com/platform/overview/), the image module uses [Netlify Image CDN](https://docs.netlify.com/image-cdn/overview/) to optimize and transform images on demand without impacting build times. Netlify Image CDN also handles content negotiation to use the most efficient image format for the requesting client.

This provider is automatically enabled in Netlify deployments, and also when running locally using [the Netlify CLI](https://docs.netlify.com/cli/local-development/).

You can also manually enable this provider. To do so, set the provider to `netlify` or add the following to your Nuxt configuration:

```ts [nuxt.config.ts]
export default defineNuxtConfig({
image: {
provider: 'netlify',
}
})
```

## Local development

To test image transformations locally, use [Netlify Dev](https://docs.netlify.com/cli/local-development/). This feature of the Netlify CLI runs a local development server that mimics the Netlify production environment, including Netlify Image CDN.

## Remote images

To transform a source image hosted on another domain, you must first configure allowed domains in your `netlify.toml` file.

```toml [netlify.toml]
[images]
remote_images = ["https://my-images.com/.*", "https://animals.more-images.com/[bcr]at/.*"]
```

The `remote_images` property accepts an array of regex. If your images are in specific subdomains or directories, you can use regex to allow just those subdomains or directories.

## Modifiers

Beyond the [standard properties](https://image.nuxt.com/usage/nuxt-img), you can use the [Netlify Image CDN `position` parameter](https://docs.netlify.com/image-cdn/overview/#position) as a modifier for Nuxt Image.

```vue
<NuxtImg
provider="netlify"
src="owl.jpg"
height="400"
width="600"
fit="cover"
format="webp"
quality="80"
:modifiers="{ position: 'left' }"
/>
```

## Deprecated Netlify Large Media option

::callout{color="amber" icon="i-ph-warning-duotone"}
Netlify’s Large Media service is [deprecated](https://answers.netlify.com/t/large-media-feature-deprecated-but-not-removed/100804). If this feature is already enabled, Large Media will continue to work on these sites as usual. New Large Media configuration is not recommended.
Netlify’s Large Media service is [deprecated](https://answers.netlify.com/t/large-media-feature-deprecated-but-not-removed/100804). If this feature is already enabled for your site on Netlify and you have already set `provider: 'netlify'` in your Nuxt configuration, then this will be detected at build time and Large Media continues to work on your site as usual. You can also explicitly enable it by setting `provider: 'netlifyLargeMedia'`. However, new Large Media configuration is not recommended.
::

Netlify offers dynamic image transformation for all JPEG, PNG, and GIF files you have set to be tracked with [Netlify Large Media](https://docs.netlify.com/large-media/overview/).
### Migrate to Netlify Image CDN

::callout
Before setting `provider: 'netlify'`, make sure you have followed the steps to enable [Netlify Large Media](https://docs.netlify.com/large-media/overview/).
::
To migrate from the deprecated Netlify Large Media option to the more robust Netlify Image CDN option, change `provider: 'netlify'` to `provider: 'netlifyImageCdn'`. This will enable the Netlify Image CDN service, even if large media is enabled on your site.

## Modifiers

In addition to `height` and `width`, the Netlify provider supports the following modifiers:
### Use deprecated Netlify Large Media option

If you're not ready to migrate to the more robust Netlify Image CDN option, Netlify continues to support dynamic image transformation for all JPEG, PNG, and GIF files you have set to be tracked with [Netlify Large Media](https://docs.netlify.com/large-media/overview/).

#### Large Media Modifiers

In addition to `height` and `width`, the deprecated Netlify Large Media provider supports the following modifiers:

### `fit`
##### `fit`

* **Default**: `contain`
* **Valid options**: `contain` (equivalent to `nf_resize=fit`) and `fill` (equivalent to `nf_resize=smartcrop`)

0 comments on commit ce84424

Please sign in to comment.