Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.

initial support for next/image on netlify #138

Merged
merged 2 commits into from
Jan 13, 2021
Merged

Conversation

lindsaylevine
Copy link
Contributor

Fixes #70

as this comment points out, this solution for initial support is not performant because the function will re-run on every request without any caching. that said, this PR is just initial support. we have performance improvements on our roadmap, depending on internal work at netlify. this PR adds this caveat to our README.

my plan, once this PR is merged, is to close #70, open a new issue that addresses performance, and update #70 so anyone from there can follow the new issue.

s/o to @jlengstorf for doing the 90% of work ahead of this PR 🙏

@lindsaylevine lindsaylevine added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Jan 9, 2021
const quality = parseInt(q);

const imageUrl = url.startsWith("/")
? `${process.env.URL || "http://localhost:8888"}${url}`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about this ||, but i think it's fine since ntl dev uses 8888 as its default port right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is probably okay in the short term, but the port is configurable. quick fix is the create a .env with URL=http://localhost:5432 or whatever to override locally


// Function used to mimic next/image and sharp
exports.handler = async (event) => {
const { url, w = 500, q = 75 } = event.queryStringParameters;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about these defaults but i think it's fine since next_image should almost always provide w

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably want some reasonable default just in case so we don't end up trying to process 6MB images at full res or whatever, but I think you're right that it should always be set

@lindsaylevine lindsaylevine merged commit b4c85b9 into main Jan 13, 2021
@lindsaylevine lindsaylevine deleted the ll/next-image branch January 13, 2021 01:55
lindsaylevine added a commit that referenced this pull request Jan 14, 2021
- Fix: fallback blocking would cause builds to crash ([#139](#139))
- next/image initial support ([#138](#138))
- generate headers file to override static chunks cache control ([#141](#141))
- track NoN files for configured dirs to clean before each run ([#134](#134))
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for Next/Image
2 participants