Browser troubleshooting

Release object URLs when a preview is finished

An object URL lets a page refer to a Blob without embedding all its bytes in a data URL. Revoke it when the preview or download no longer needs it, not immediately before the consumer can load it.

Worked example

Browser console example · use a disposable page on your own site

const blob = new Blob(["temporary preview"], {type: "text/plain"});
const url = URL.createObjectURL(blob);
console.log(url.startsWith("blob:"));
// After the consuming preview has been removed or finished:
URL.revokeObjectURL(url);

How it works

The browser keeps a mapping from the generated URL to the Blob. Revoking removes that mapping so its resources can be released when no longer needed. A real preview should retain the URL for as long as the visible consumer relies on it.

Limits and mistakes

Revocation is not deletion of the original user file. For an initiated download, do not revoke synchronously before the browser can consume the resource; tie cleanup to an appropriate lifecycle. Repeated previews need cleanup for earlier URLs too.

Check the result

Expect true. In a preview implementation, replace the file several times and confirm old previews are removed and old URLs revoked only after their consumers are finished.

Sources

Reference documentation for the behavior used in this guide: