Skip to content

AWS Amplify Failing to Load .webp pictures

2

i have a REact SPA website that is hosted with AWS amplify and its been working great for a year or so. I changed some of my .png and .jpeg images to .webp and now they are failing to load. I have checked the redirect rules to include .webp in the regex (</^[^.]+$|\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|woff2|ttf|map|json|webp)$)([^.]+$)/>). Also the images are showing in a local VITE build.

I can even get the image from my terminal with curl -I

curl -I https://acme.com
HTTP/2 302 
location: https://www.acme.com/
date: Mon, 09 Dec 2024 04:23:02 GMT
x-cache: Miss from cloudfront
via: 1.1 91356d2137f5a7345e93da4516c49ec4.cloudfront.net (CloudFront)
x-amz-cf-pop: SEA73-P1

me@ThinkPad-P51:~$ curl -I https://acme.com/assets/people-tutoring-hero-4kQ2o2Y1.webp
HTTP/2 302 
location: https://www.acme.com/assets/people-tutoring-hero-4kQ2o2Y1.webp
date: Mon, 09 Dec 2024 04:23:25 GMT
x-cache: Miss from cloudfront
via: 1.1 567b44ed19c8caed2570b7bcd8c70034.cloudfront.net (CloudFront)
x-amz-cf-pop: SEA73-P

me@ThinkPad-P51:~$ curl -I https://www.acme.com/assets/people-tutoring-hero-4kQ2o2Y1.webp

curl -I https://www.acme.com/assets/people-tutoring-hero-4kQ2o2Y1.webp
HTTP/2 200 
content-type: image/webp
content-length: 1044796
date: Mon, 09 Dec 2024 04:23:39 GMT
server: AmazonS3
accept-ranges: bytes
etag: "450e68327c9208c942a386e96782b720"
last-modified: Sun, 08 Dec 2024 21:33:27 GMT
cache-control: public, max-age=0, s-maxage=31536000
x-cache: Miss from cloudfront
via: 1.1 73cb83fe6699afc2791b5c690c1ff8c6.cloudfront.net (CloudFront)
x-amz-cf-pop: SEA73-P1
alt-svc: h3=":443"; ma=86400
x-amz-cf-id: 0Ac17RjlrLZwQ-lwnfXmJYXez87-mFsZz7x9OYATLKp3Fh3OoR1c7A==

So why is now webp not working with the website?

2 Answers
1

For my case

This was rewrite rule exist

[ { "source": "/<*>", "status": "404-200", "target": "/index.html" }, { "source": "</^[^.]+$|\\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map|json)$)([^.]+$)/>", "status": "200", "target": "/index.html" } ]

I added to support webp in same rule and redeploy and its works

[ { "source": "/<*>", "status": "404-200", "target": "/index.html" }, { "source": "</^[^.]+$|\\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map|webp|json)$)([^.]+$)/>", "status": "200", "target": "/index.html" } ]

answered a year ago

0

The issue you're experiencing with .webp images not loading on your AWS Amplify-hosted React SPA website, despite working locally and being accessible via curl, could be due to a few potential reasons:

  1. MIME Type Configuration: Ensure that your AWS Amplify configuration properly recognizes and serves .webp files with the correct MIME type (image/webp). Sometimes, servers may not be configured to serve newer file formats correctly.

  2. Caching Issues: Your browser or CDN might be caching an older version of the site or its assets. Try clearing your browser cache or forcing a cache invalidation on the Amplify side.

  3. Build Process: Verify that your build process is correctly handling and including .webp files. Sometimes, build configurations might need to be updated to process new file types.

  4. Content-Type Header: Check if the Content-Type header for .webp files is set correctly when served by Amplify. Your curl output shows it's correct, but double-check this in your browser's network tab.

  5. Redirect Rules: While you've updated the redirect rules to include .webp, ensure there are no conflicting rules that might be preventing these files from being served correctly.

  6. CloudFront Configuration: If you're using CloudFront, make sure its configuration is updated to handle .webp files correctly, including any custom behaviors or cache settings.

  7. Browser Support: Although unlikely given it works locally, ensure that the browsers you're testing with support .webp format.

To troubleshoot:

  • Check your Amplify build logs for any warnings or errors related to .webp files.
  • Use browser developer tools to inspect network requests for these images and look for any error responses or unexpected redirects.
  • Verify that the .webp files are actually being uploaded to the correct location in your Amplify-hosted environment.
  • Try temporarily disabling any custom routing or redirect rules to see if that resolves the issue.

If none of these solve the problem, you may need to contact AWS support for more specific assistance with your Amplify configuration.
Sources
AWS Amplify | Extensible Web & Mobile Apps | Amazon Web Services
Troubleshooting | Amplify UI for React

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.