Skip to content

Commit

Permalink
fix: cache problem (final attempt?)
Browse files Browse the repository at this point in the history
  • Loading branch information
tc-imba committed Jun 25, 2024
1 parent 5c8f30d commit 685205a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions example/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
pathPrefix: '/gatsby-theme-academic',
pathPrefix: '/',
siteUrl: 'https://tc-imba.github.io',
title: 'John Doe',
description: 'Personal Website of John Doe',
Expand All @@ -8,7 +8,7 @@ module.exports = {
introduction: [
'You can write one or several paragraphs to introduce yourself here. You can find this introduction in the `config.js` file in the template.',
'In this site, almost everything supports Markdown Syntax. For example, you can add hyperlinks in the introduction such as [fxhsb](https://github.com/Reapor-Yurnero) with\n```markdown\n[fxhsb](https://github.com/Reapor-Yurnero)\n```',
'Here we try to test whether reloading is enabled when site updated (4).',
'Here we try to test whether reloading is enabled when site updated (19).',
],
avatar: 'avatar.png',
professions: [
Expand Down
11 changes: 6 additions & 5 deletions gatsby-theme-academic/gatsby-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import {

export const wrapPageElement = _wrapPageElement;

// trigger an immediate page refresh when an update is found
export const onServiceWorkerUpdateFound = () => {
console.log('update found, reload the page');
window.location.reload();
export const onRouteUpdate = () => {
window.navigator.serviceWorker.register('/sw.js').then((reg) => {
reg.update();
});
};

// trigger an immediate page refresh when an update is found
export const onServiceWorkerUpdateReady = () => {
console.log('update found, reload the page');
window.location.reload();
window.location.reload(true);
};
5 changes: 5 additions & 0 deletions gatsby-theme-academic/gatsby-config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import remarkAbbr from 'remark-abbr';
import remarkExternalLinks from 'remark-external-links';
import remarkGfm from 'remark-gfm';
import remarkMath from 'remark-math';
import moment from 'moment';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const buildTime = moment().format();

const config = ({
contentPath = 'content',
Expand Down Expand Up @@ -86,6 +88,9 @@ const config = ({
options: {
name: author,
short_name: author,
// we must add buildTime (or anything different at each build)
// to force refresh the service worker in gatsby-plugin-offline
description: `Build at ${buildTime}`,
start_url: '/',
background_color: '#304CFD',
theme_color: '#304CFD',
Expand Down

0 comments on commit 685205a

Please sign in to comment.