Skip to content

Commit

Permalink
Fix for the client-side caching breaking GeoJSON sources (#82)
Browse files Browse the repository at this point in the history
* RD-254 Fix for the client-side caching breaking GeoJSON (and video) sources

* Add changelog entry
  • Loading branch information
petrsloup authored Apr 24, 2024
1 parent 14baf8e commit db79e06
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## DEVEL
### New Features
### Bug Fixes
- Fix for the client-side caching breaking GeoJSON sources [#82](https://github.com/maptiler/maptiler-sdk-js/pull/82)
### Others

## NEXT
Expand Down
10 changes: 6 additions & 4 deletions src/caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function localCacheTransformRequest(
config.session &&
reqUrl.host === defaults.maptilerApiHost
) {
if (resourceType == "Source") {
if (resourceType == "Source" && reqUrl.href.includes("tiles.json")) {
return reqUrl.href.replace(
"https://",
`${LOCAL_CACHE_PROTOCOL_SOURCE}://`,
Expand Down Expand Up @@ -74,9 +74,11 @@ export function registerLocalCacheProtocol() {
const response = await fetch(params.url, requestInit);
const json = await response.json();

// move `Last-Modified` to query so it propagates to tile URLs
json.tiles[0] +=
"&last-modified=" + response.headers.get("Last-Modified");
if (json.tiles && json.tiles.length > 0) {
// move `Last-Modified` to query so it propagates to tile URLs
json.tiles[0] +=
"&last-modified=" + response.headers.get("Last-Modified");
}

return {
data: json,
Expand Down

0 comments on commit db79e06

Please sign in to comment.