unjs / ipx

🖼️ High performance, secure and easy-to-use image optimizer.
MIT License
1.54k stars 61 forks source link

fix: serialize src in cache adapter #22

Closed atinux closed 3 years ago

atinux commented 3 years ago

I found an issue with cacheKey of IPX when image depends of query parameters.

I am using https://eu.ui-avatars.com/ for avatars on Nuxt Image demo.

Example:

The issue is that IPX will cache the first Image since we actually split with # or ?, see https://github.com/nuxt-contrib/ipx/blob/11d1e1aa86350a9f095a175844a09a0f9a6b598b/src/input/remote.ts#L32

This PR fixes it by moving the key generation in the cache adapter directly (should not create any issue for FS adapter), this way we also have the cache directory with only files inside and no sub directories.

I found shorthash2 quite nice, rewritten in TS with a simple implementation.

atinux commented 3 years ago

Also related: https://github.com/nuxt/image/issues/173

pi0 commented 3 years ago

(covered by rewrite)