Request for image between routers
Answered
Orinoco Crocodile posted this in #help-forum
Orinoco CrocodileOP
I have simple app
https://test-git-main-karina1703.vercel.app/
When I routing between pages, there is a request for an image, shouldn't this be cached?
My image looks like that
https://test-git-main-karina1703.vercel.app/
When I routing between pages, there is a request for an image, shouldn't this be cached?
My image looks like that
<Image src="/next.svg" width={100} height={100} alt="next"></Image>Answered by riský
yeah they now send 304 Not Modified for me (my issue was that I forgot to disable "disable cache" in chrome)
50 Replies
from the screenshot we cannot tell, network debug tool may show a request even when it hits the cache
i can't reproduce this with that link, it fetches it once and then no more even when clicking "dish123" and "home"
are you using dev mode to get that screenshot?
@Julienng It seems like it is cached by vercel cdn but not cached by the browser
Orinoco CrocodileOP
do you also have multiple image requests between routes?
@riský i can't reproduce this with that link, it fetches it once and then no more even when clicking "dish123" and "home"
Orinoco CrocodileOP
Stange thing. This screenshot from prod
https://test-git-main-karina1703.vercel.app/
https://test-git-main-karina1703.vercel.app/
i am using firefox if that means anything...
ill check edge (basicly chrome)
ahh yes i do see this now
@riský i am using firefox if that means anything...
Orinoco CrocodileOP
In safari I have the same situation. But after all on a default so should not occur?
some reason it has the no cache headers on the result:
Cache-Control: no-cacheare you not using optiomised images form next/image
@riský some reason it has the no cache headers on the result:
Cache-Control: no-cache
Orinoco CrocodileOP
do you know how to prevent it?
@riský are you not using optiomised images form next/image
Orinoco CrocodileOP
yes, i do
im assuming your using public folder to store the svg
Orinoco CrocodileOP
import Image from "next/image";
import Link from "next/link";
import React from "react";
const page = () => {
return (
<div>
<Link href="dish/123">Dish 123</Link>
<Image src="/next.svg" width={100} height={100} alt="next"></Image>
</div>
);
};
export default page;
import Link from "next/link";
import React from "react";
const page = () => {
return (
<div>
<Link href="dish/123">Dish 123</Link>
<Image src="/next.svg" width={100} height={100} alt="next"></Image>
</div>
);
};
export default page;
@riský im assuming your using public folder to store the svg
Orinoco CrocodileOP
yep
well, this seems like vercel isn't caching it, so i don't know of anything that can help you, sorry
Orinoco CrocodileOP
thank you!
@Orinoco Crocodile actually, https://github.com/vercel/next.js/discussions/16118 suggests that you can override those headers and set them to cache
but thats old so idk (i haven't tested it)
so you might be able to
https://nextjs.org/docs/pages/api-reference/next-config-js/headers#header-cookie-and-query-matching
use the headers thing and make that image cached (but i don't know how well it works for files also)
https://nextjs.org/docs/pages/api-reference/next-config-js/headers#header-cookie-and-query-matching
use the headers thing and make that image cached (but i don't know how well it works for files also)
@riský so you might be able to
<https://nextjs.org/docs/pages/api-reference/next-config-js/headers#header-cookie-and-query-matching>
use the headers thing and make that image cached (but i don't know how well it works for files also)
Orinoco CrocodileOP
I am already tried to set request headers, but it is not work for me. But I will try again. Thank you very much! I use app folder, maybe it is bug
yeah i didn't expect it to work, but heppy to try and help 🙂
@Orinoco Crocodile whatever your update was (it looks diferent now), my chrome isn't requesting it after page change (just the inital time)
@riský <@490616037654659075> whatever your update was (it looks diferent now), my chrome isn't requesting it after page change (just the inital time)
Orinoco CrocodileOP
which version do you have?
I have new Version 116.0.5845.96 (Official Build) (arm64)
uhh Microsoft Edge: Version 116.0.1938.54 (Official build) beta (64-bit)
i don't see how that would change much tho
Orinoco CrocodileOP
hmm
The vercel behavior is correct : https://vercel.com/docs/edge-network/caching#static-files-caching
- default cache control : public, max-age=0, must-revalidate
- cache at the edge by vercel like in my screenshot (x-vercel-cache: HIT)
- default cache control : public, max-age=0, must-revalidate
- cache at the edge by vercel like in my screenshot (x-vercel-cache: HIT)
yeah i think it is working now 🙂
Orinoco CrocodileOP
but this is not the best user experience - every time we request an image
You can change the vercel behavior here (I assume) : https://nextjs.org/docs/app/api-reference/components/image#caching-behavior
@Julienng You can change the vercel behavior here (I assume) : https://nextjs.org/docs/app/api-reference/components/image#caching-behavior
Orinoco CrocodileOP
I already tried this
images: {
minimumCacheTTL: 60,
},
And it is not work for me
images: {
minimumCacheTTL: 60,
},
And it is not work for me
@Orinoco Crocodile but this is not the best user experience - every time we request an image
The CDN should be pretty close to the user, it will respond pretty fast. You can check it works with : x-vercel-id. For me, it's cdg1 zone. I'm always < 20ms on my tests with your deployment
I find it pretty nice from an app standing point. Your image responds in less than 20-50ms most of the time and you can control caching behavior from the CDN easily
yeah they now send 304 Not Modified for me (my issue was that I forgot to disable "disable cache" in chrome)
Answer
@riský yeah they now send 304 Not Modified for me (my issue was that I forgot to disable "disable cache" in chrome)
Orinoco CrocodileOP
you know, I forgot about it too
but I have the same problem in safari
But not in chrome 🙂
well then its not proabibly nextjs/vercels issue but safari 

@riský well then its not proabibly nextjs/vercels issue but safari <:lolsob:753870958489632819>
Orinoco CrocodileOP
safari is always problematic 🙂
@Julienng The CDN should be pretty close to the user, it will respond pretty fast. You can check it works with : x-vercel-id. For me, it's cdg1 zone. I'm always < 20ms on my tests with your deployment
Orinoco CrocodileOP
yep, you are right, thank you too
so i think you can mark this as solved?
@riský so i think you can mark this as solved?
Orinoco CrocodileOP
I think yes. I spend two days on it 

ahah
Original message was deleted
just folow this guide and choose any message that is the "answer"...
@riský just folow this guide and choose any message that is the "answer"...
Orinoco CrocodileOP
by the way, did you use sprites in next?
svg sprites