Skip to content

Seeking Workarounds: How to force-refresh pdf.worker.js in Production (Version Mismatch/ Corrupted PDF) #306

@sujithsundaranaspire

Description

@sujithsundaranaspire

We are encountering a persistent issue where pdf.worker.js remains cached in the browser (Chrome/Edge) even after a new deployment. This results in a "Version Mismatch" or a "Corrupted PDF" error because the newer viewer.jd is trying to communicate with an outdated, cached worker.

The problem:
Standard window.location.reload() does not clear the worker cache.
The issue persists even in Incoginito mode (Chromium behaviour)
Only manually "Clearing Application Storage" in DevTools resolves the issue.
Since the worker is copied from node_modules into assets/ During build, it lacks the unique hashing that Angular applies to main bundles.

Request for Workarounds:
Has anyone successfully implemented a workaround to force the browser to fetch a fresh version of the worker without manually renaming folders in angular.json for every build?

Specifically, I am looking for advice on:
Injection Hooks: Is there a way to intercept the worker loading in ng2-pdfjs-viewer to append a query parameter (e.g., ?v=123) to the worker url?

Environment:
Library:ng2-pdfjs-viewer@20.0.0
Framework: Angular 20+
Browsers: Microsoft Edge, Google Chrome

Any snippets or architectural patterns would be greatly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions