Some JS assets return `CDN object Not Found` from cloudfront with optimization

Jekyll site. When optimization disabled there’s no issue. But when enabled any JS asset which is in a path like /foo/bar/hello.js returns the CDN object Not Found from cloudfront error. But all assets in /js/ are served fine.

Are assets not allowed more that one directory deep?

Hi :wave:t6:, thanks so much for reaching out to us and welcome to the forums!

We have a similar thread in the forums: JaveScript Asset 404 Error after Asset Optimization Feature Enabled, a user reported an where a JavaScript file was redirected to CloudFront and caused a 404 error when Asset Optimization was enabled. The support response suggested that the issue was not with Netlify, but with the way the script was requesting the file from the origin server.

Our Netlify documentation also mentions that enabling asset optimization can sometimes cause issues with the paths of assets.

If you’re experiencing similar issues, you might want to try disabling asset optimization to see if that resolves the problem. You can do this by going to Site settings > Build & deploy > Post processing > Asset optimization in your Netlify dashboard.