mapbox / mapbox/mapbox-gl-js

When Cache API is not available, dont clone response for `cachePut`

Open
#8,416 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug :lady_beetle: good first issue
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

The `cacheGet` method calls back to `validateOrFetch` with a `null` error if `window.caches` is not available. From what I can tell, this could happen when the `Cache` API is not available at all or if a page is served over `http` and the `Cache` API is not usable.

https://github.com/mapbox/mapbox-gl-js/blob/dd5dcd025a5465e85330ac564a27d3a4b60839dc/src/util/tile_request_cache.js#L72-L81

In this case `validateOrFetch` still calls clones the response and attempts to place it in the cache.

https://github.com/mapbox/mapbox-gl-js/blob/dd5dcd025a5465e85330ac564a27d3a4b60839dc/src/util/ajax.js#L127-L131

If it is known that `window.caches` is no available or usable, there is not need to clone the response or to load its contents:

https://github.com/mapbox/mapbox-gl-js/blob/dd5dcd025a5465e85330ac564a27d3a4b60839dc/src/util/ajax.js#L144-L152

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/util/tile_request_cache.js at the linked cacheGet and validateOrFetch flow, then read src/util/ajax.js at the linked response-handling sections. Verify the behavior when window.caches is unavailable or unusable; done means cachePut does not clone the response or load its contents in that case.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend, performance
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.