In my setup with Next.js version 13,
I have stored my build in a bucket.
My goal is to ensure that the user's browser always fetches the latest build of my static site. However, I'm facing an issue where each folder/page on the website has an index.txt file that is cached for 1 hour in the browser. This file seems crucial for updates and rebuilds, as it plays a significant role. Surprisingly, this file remains unaffected by the custom generateBuildId() function in next.config.js.
Instead of adjusting the cache settings in the bucket for individual files,
I devised a script that modifies every path in files containing index.txt to include a query parameter indicating the latest version.
Therefore, after building, I run a bash script (which locates index.txt and appends ?v={my version here} to it):
find out -type f -exec grep -q "index.txt" {} \; -exec sed -i '' -e "s/index.txt/index.txt%3Fv=$(date +%s)/g" {} \;
This approach successfully updates my
out/_next/static/chunks/139-72884d103bad554b.js
file.
However, when attempting to access these files with the encoded URL like
mywebsite.com/index.txt%3Fv=1234567
, the browser encounters a 404
error.
Is there a way in Next.js 13 to perform SSG rebuilds and apply new versions to all files (including .txt files)?
Alternatively, is there a method to add ?v={buildId}
to all asset dependencies so that the browser does not encode it?
Or perhaps there is another strategy to prompt browsers to refetch content after a rebuild?
Thank you sincerely,