Skip to content

Commit

Permalink
Merge pull request #36 from FokkoVeegens/16-prevent-caching-of-data-json
Browse files Browse the repository at this point in the history
Add cache buster to data fetch to prevent caching issues
  • Loading branch information
FokkoVeegens authored Jan 9, 2025
2 parents 147569e + 6a94508 commit 5de052d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"vite-plugin-html": "^3.2.2",
"vite-plugin-rewrite-all": "^1.0.2"
}
}
}
10 changes: 4 additions & 6 deletions src/utils/getData.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ import basename from "../../react-config";
let cachedData = null;

const getData = async () => {
if (cachedData) {
return cachedData;
}
try {
const response = await fetch(`${basename}data.json`);
// Fetch the file hash without caching
const response = await fetch(`${basename}data.json`, { cache: 'no-store' });
if (!response.ok) {
throw new Error('Network response was not ok');
}
cachedData = await response.json();
return cachedData;
const data = await response.json();
return data;
} catch (error) {
console.error('Fetch error:', error);
throw error;
Expand Down

0 comments on commit 5de052d

Please sign in to comment.