Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/pxweb2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
href="./images/favicon-darkmode.svg"
/>
<link rel="stylesheet" href="src/styles.scss" />
<link rel="stylesheet" href="./theme/variables.css" />
<link rel="stylesheet" href="./theme/variables.css?v=__BUILD_DATE__" />
<link
rel="preload"
href="./fonts/PxWeb-font-500.ttf"
Expand All @@ -35,7 +35,7 @@
crossorigin="anonymous"
type="font/ttf"
/>
<script src="./config/config.js"></script>
<script src="./config/config.js?v=__BUILD_DATE__"></script>
</head>
<body>
<div id="root"></div>
Expand Down
9 changes: 6 additions & 3 deletions packages/pxweb2/src/app/util/content/localeContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ export async function fetchLocaleContent(
// 3) Start fetch and memoize the in-flight promise
const fetchPromise = (async () => {
try {
const res = await fetch(`./content/${key}/content.json`, {
cache: 'no-store',
});
const res = await fetch(
`./content/${key}/content.json?v=${__BUILD_DATE__}`,
{
cache: 'no-store',
},
);
if (!res.ok) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/pxweb2/src/app/util/hooks/useTopicIcons.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react';

const ICON_MAP_URL = './icons/topicIconMap.json';
const ICON_MAP_URL = `./icons/topicIconMap.json?v=${__BUILD_DATE__}`;
const ICON_BASE_PATH = './icons/topic';

export type TopicIconComponents = {
Expand Down
2 changes: 1 addition & 1 deletion packages/pxweb2/src/i18n/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const initPromise = i18n
.use(languageDetector)
.init({
backend: {
loadPath: `${config.baseApplicationPath}locales/{{lng}}/translation.json`,
loadPath: `${config.baseApplicationPath}locales/{{lng}}/translation.json?v=${__BUILD_DATE__}`,
},
fallbackLng: config.language.fallbackLanguage,
defaultNS,
Expand Down
16 changes: 12 additions & 4 deletions packages/pxweb2/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ const themeInjectorPlugin = (): Plugin => ({
transformIndexHtml(html) {
// Remove the theme CSS link from the original HTML
html = html.replace(
'<link rel="stylesheet" href="./theme/variables.css" />',
'<link rel="stylesheet" href="./theme/variables.css?v=__BUILD_DATE__" />',
'',
);

// Inject it at the end of head to ensure it loads last
return html.replace(
html = html.replace(
'</head>',
'<link rel="stylesheet" href="./theme/variables.css" /></head>',
'<link rel="stylesheet" href="./theme/variables.css?v=__BUILD_DATE__" /></head>',
);
// Replace cache busting build date placeholder
return html.replace(/__BUILD_DATE__/g, new Date().toISOString());
},
});

Expand Down Expand Up @@ -45,4 +46,11 @@ export default defineConfig({
$ui: path.resolve('../pxweb2-ui/'),
},
},
define: {
// Used for cache busting of configuration files.
// Since we don't update pkg.version on release yet, we use build date instead.
// import pkg from './package.json';
// __BUILD_VERSION__: JSON.stringify(pkg.version),
__BUILD_DATE__: JSON.stringify(new Date().toISOString()),
},
});