Yes. this works great if you are navigating between inertia pages. however if you go to the page and reload it, it will not preload the image.
Jan 14, 2026
2
Level 1
Preloading images via injecting preload link in response header
Hello,
I want to preload images on my Laravel application before rendering the Vue template, so I worked on this middleware
public function handle(Request $request, Closure $next): Response
{
$response = $next($request);
if ($request->header('X-Inertia')) {
return $response;
}
$preloads = $request->attributes->get('preload_images', []);
foreach ($preloads as $url) {
$response->headers->set(
'Link',
"<{$url}>; rel=preload; as=image; fetchpriority=high",
false
);
}
return $response;
}
Which sets preloads links on the response header. it worked fine. the problem is that it is re-loading the image after rendering the vue page.
Is there a way to get around this?
Thank you.
Please or to participate in this conversation.