Skip to content

Why we not use the full image url as cache key? #206

@chriszyyy

Description

@chriszyyy

The logic of caching image url is not working as expected
See here the source code of the issue https://github.com/bubkoo/html-to-image/blob/master/src/getBlobFromURL.ts#:~:text=let%20key%20%3D%20url.replace(/%5C%3F.*/%2C%20%27%27)

function getCacheKey(url: string) {
  let key = url.replace(/\?.*/, '')

  // font resourse
  if (/ttf|otf|eot|woff2?/i.test(key)) {
    key = key.replace(/.*\//, '')
  }

  return key
}

If the image use query string to distinguish which image to get, that image all same format image with used the wrong cached one.

For example:

  1. https://www.abc.com/images?id=123
  2. https://www.abc.com/images?id=124

The second one will render with the first image because of the cache logic

Expected Behavior

We should use the full URL as key to cache.

Current Behavior

It only use the URL with domain and path, not query string.

Possible Solution

Remove let key = url.replace(/\?.*/, '')

Your Environment

  • html-to-image: 1.9.0
  • OS: Win10
  • Browser: chrome

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions