How to make sure requests are correctly cache busted

We run PDF.js Express 7.1.0 and have a question about cache busting.

Our servers are set to browser cache all static assets for a long time and some assets are even loaded from CDN servers to speed up and cache even more.

However, this also brings us a problem with PDF.js Express since we have core & ui & legacy-ui folders copied from NPM to our public folder, however PDF.js Express does not add any query parameters to the request of these files which would serve older versions of those files to users once we upgrade PDF.js Express, and that would be a shame ofcourse since that could possibly break the web viewer.

It would be great if PDF.js Express would append ?v=7.1.0 (when the version is 7.1.0) to all static assets that are being included, or allow us to supply a version number to append to each url.

Other option would be to not host it at site.com/pdfjsexpress/ui but at site.com/pdfjsexpress/7.1.0/ui however I am not sure I can get NPM to export it like that.

Hope to hear how others have solved this or if there is a “official” suggestion on how to solve this.

Hi!

We usually recommend that you change the name of the folder the assets are stored in.

So if you were using version 7.0 your assets would live in yourwebsite.com/7.0/lib. When upgrading to 7.1 you would change that to yourwebsite.com/7.1/lib.

You would just have to change the script you are using to copy these files to include the version number in the path.

I hope this helps!
Thanks,
Logan

Okay sounds good. Since we are using Yarn I’ve done the following (in case other readers find this interesting).

Added this script to the scripts:

"move-static": "PDFJS_EXPRESS_VERSION=`yarn info -s @pdftron/pdfjs-express version` && rm -Rf ./public/js/pdfjsexpress/$PDFJS_EXPRESS_VERSION && mkdir -p ./public/js/pdfjsexpress/$PDFJS_EXPRESS_VERSION && cp -af ./node_modules/@pdftron/pdfjs-express/public/. ./public/js/pdfjsexpress/$PDFJS_EXPRESS_VERSION && cp -af ./node_modules/@pdftron/pdfjs-express/webviewer.min.js ./public/js/pdfjsexpress/$PDFJS_EXPRESS_VERSION/webviewer.min.js"

This should move the required files to ./public/js/pdfjsexpress/7.1.0 when version 7.1.0 is installed.

We have the version pinned to 7.1.0 (or whatever version we want) and we repeat that version number in our application config so we can use the version number when referencing the files in the HTML output.

1 Like