Comments (9)
Thanks for reporting, I will try to reproduce this behaviour with some of our examples later today.
Assets served from the prefix _next/static/*
should not be part of any invalidation.
from terraform-aws-next-js.
from terraform-aws-next-js.
Thanks for sharing!
The invalidations seem intentional here because these are assets uploaded from the public/
folder I guess.
While it is a valid use case to serve assets from the public folder, I recommend importing assets from the code, so that Next.js can optimize (append a hash to the filename) them for usage together with a CDN.
// Icon.js
import noEntryIcon from './assets/icons8-no-entry.svg`
export default function MyIconComponent() {
return <img src={noEntryIcon} />
}
Doing it this way, Next.js will output the asset as something like _next/static/.../icons8-no-entry.2fdhad82.svg
which is an immutable route thanks to the unique hash 2fdhad82
appended to the filename.
So when the file changes, Next.js will append a new hash, which also produces a new route on the CDN.
However what is bad here, is that we don't check if the content of the file has actually changed when doing a deployment.
So when I have a file public/favicon.ico
and I don't change the file between two deployments I would expect that no invalidation is issued for this file.
Looking at the screenshot, the only actual route that gets invalidated is /404
.
Are the other routes served by Lambdas (SSR) is that the bug you are describing here?
from terraform-aws-next-js.
Thanks for your detailed reply. The point with the assets is fair. We definitely gonna change that. However, the problem that we're facing is that the pre-rendered Html doesn't get invalidated, which results in no changes apply on our website until I manually trigger an invalidation for all directories in CloudFront.
from terraform-aws-next-js.
I've just been having a brief look into your code. In the create-invalidation.js
you limit the paths to 15 per invalidation and then invalidate in batches. Unfortunately, for me, there is always just one invalidation happening. Could this be a possible issue?
from terraform-aws-next-js.
Yes, that's my assumption what is happening here 👍
I also left a todo in the code, because we never actually checked a case with more than 15 invalidations.
https://github.com/dealmore/terraform-aws-next-js/blob/ad7047c94fa5025e448056361de8fa5cd65b42f4/packages/deploy-trigger/src/create-invalidation.ts#L9
from terraform-aws-next-js.
Ok. So, just to clarify (I'm new to next-js), is it considered best practice to load all assets from the code via webpack? I played around with a few libraries, tried next-images
which seems to work but didn't find any for fonts. Also, will this be working with nextjs 10 image objects?
from terraform-aws-next-js.
As for all in software it depends 😄
Loading assets via webpack is recommended for assets that you know your application needs at build time, Things like icons, css-background-images or webfonts fall into this category.
Importing them is not limited to JavaScript code. For example you can also load webfonts directly from your CSS:
@font-face {
font-family: 'Montserrat';
font-style: normal;
font-weight: 500;
src: local(''),
url('./fonts/montserrat-v15-latin-500.woff2') format('woff2')
}
I think you don't need any additional configuration, since loading assets is already built-in in Next.js (and the underlaying webpack configuration). The important thing here is to use relative paths (./fonts/montserrat-v15-latin-500.woff2
) instead of absolute paths (/fonts/montserrat-v15-latin-500.woff2
) so that webpack can check for the referenced files on your local filesystem at build time.
from terraform-aws-next-js.
Well, for sure it always "depends", however, when you're using a framework it is usually opinionated and there are best practices. The next.js documentation explicitly advises to put build time assets in the public folder:
https://nextjs.org/docs/basic-features/static-file-serving
As far as I read it from the documentation the next-jst10 next/image
component also relies on images are stored in the public folder, however, I might be wrong here, I'm not a frontend dev.
from terraform-aws-next-js.
Related Issues (20)
- Modify proxy to force a version change HOT 1
- Unable to attach policy to lambda, since the iam.tf is missing in all versions starting from 1.0.0-canary.2 HOT 1
- Error: Authentication Failed Returns Status Code 0
- What services does this library use internally to manage deployments? HOT 1
- Unable to use redirect inside getServerSideProps HOT 3
- [Bug] Error while using middleware from Next 12.2 HOT 1
- TimeoutError: Promise timed out after 300000 milliseconds HOT 1
- Question: how can I use this module if I am using Cloudflare for DNS management and WAF? HOT 2
- Dynamic Routes like [id].tsx doesn't be update in my github action
- Q: What permissinos are needed for deployment? HOT 1
- Next.js v13 support HOT 10
- One or more of the CNAMEs you provided are already associated with a different resource. HOT 1
- Cannot deploy - .next-tf/lambdas\__NEXT_PAGE_LAMBDA_0.zip: no such file or directory HOT 1
- Is there a localstack sample available? HOT 1
- Getting Error during creating resources with terraform
- Deployment not deletes old files from s3 HOT 1
- NextAuth CLIENT_FETCH_ERROR , NEXTAUTH_URL
- New deployments not possible due as AWS ACLs are disabled by default HOT 1
- Alternatives? HOT 2
- Lambda functions no longer support NodeJS `v14` . HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terraform-aws-next-js.