Skip to content

Build your personal knowledge base with Trilium Notes

fix(pdf): cache buster not working in all circumstances

Elian Doran8c1a58e64f85
diff --git a/apps/client/src/widgets/type_widgets/file/PdfViewer.tsx b/apps/client/src/widgets/type_widgets/file/PdfViewer.tsx
index e00d0e9079..0780a75d72 100644
--- a/apps/client/src/widgets/type_widgets/file/PdfViewer.tsx
+++ b/apps/client/src/widgets/type_widgets/file/PdfViewer.tsx
@@ -38,7 +38,7 @@ export default function PdfViewer({ iframeRef: externalIframeRef, pdfUrl, onLoad
ref={iframeRef}
class="pdf-preview"
style={{width: "100%", height: "100%"}}
- src={`pdfjs/web/viewer.html?file=${pdfUrl}&lang=${locale}&sidebar=${newLayout ? "0" : "1"}&editable=${editable ? "1" : "0"}`}
+ src={`pdfjs/web/viewer.html?v=${glob.triliumVersion}&file=${pdfUrl}&lang=${locale}&sidebar=${newLayout ? "0" : "1"}&editable=${editable ? "1" : "0"}`}
onLoad={() => {
injectStyles();
onLoad?.();
diff --git a/packages/pdfjs-viewer/scripts/build.ts b/packages/pdfjs-viewer/scripts/build.ts
index 2728013463..496258b0b2 100644
--- a/packages/pdfjs-viewer/scripts/build.ts
+++ b/packages/pdfjs-viewer/scripts/build.ts
@@ -71,13 +71,17 @@ function patchCacheBuster(htmlFilePath: string) {
const version = packageJson.version;
console.log(`Versioned URLs: ${version}.`)
let html = readFileSync(htmlFilePath, "utf-8");
- html = html.replace(
- `<link rel="stylesheet" href="custom.css" />`,
- `<link rel="stylesheet" href="custom.css?v=${version}" />`);
- html = html.replace(
- `<script src="custom.mjs" type="module"></script>`,
- `<script src="custom.mjs?v=${version}" type="module"></script>`
- );
+ for (const file of [ "viewer.css", "custom.css" ]) {
+ html = html.replace(
+ `<link rel="stylesheet" href="${file}" />`,
+ `<link rel="stylesheet" href="${file}?v=${version}" />`);
+ }
+ for (const file of [ "viewer.mjs", "custom.mjs" ]) {
+ html = html.replace(
+ `<script src="${file}" type="module"></script>`,
+ `<script src="${file}?v=${version}" type="module"></script>`
+ );
+ }
writeFileSync(htmlFilePath, html);
}