bigcommerce / paper-handlebars

Paper plugin for rendering via Handlebars.js
BSD 4-Clause "Original" or "Old" License
12 stars 36 forks source link

fix: MERC-9364 Use CDN Original images for webdav - cache control #298

Open christensenep opened 8 months ago

christensenep commented 8 months ago

What? Why?

Use CDN Original images for webdav - cache control. Take 2. See https://github.com/bigcommerce/paper/pull/343

If a developer/merchant uses the cdn handlebars helper to inject images from webdav into the theme using e.g.({{cdn "webdav:/img/image.jpg"}}), there is no cache-control header when the image is fetched on the storefront.

Similar to our Image Manager, we should be using the cdn original images (Similar to Jinsoo's PR here MERC-7127)

This PR differs from the previous as it only does this for file suffixes that image manager supports (jpg/jpeg/png/gif). This avoids the issue where the url is changed for e.g. a pdf, and thus creates a broken link.

How was it tested?

Tested locally and in integration, and with unit tests. Have verified that images (png/gif/jpeg/jpg) uploaded to the content directory via webdav can be accessed at their cache-controlled url using the cdn helper (/images/stencil/original/content/<whatever>), while all other file extensions still return the /content/<whatever> path when using the helper.

Behold, the results of outputting some of these urls directly to the DOM: Screenshot 2024-01-11 at 4 40 25 PM

cc @bigcommerce/storefront-team

christensenep commented 8 months ago

♻️ I have tested this with gifs, jpeg/jpgs and pngs, and verified that the new urls are valid and have cache control headers. I have also verified that other file extensions such as pdfs and, importantly, bmps do not change the url from its current form and are thus still valid. I also verified that bmps do not have the images/stencil/content form of the url available, so I believe this is the correct and exhaustive of extensions we should be doing this for.

christensenep commented 8 months ago

@bigcommerce/team-merchandising @bigcommerce/team-storefront