Skip to content

feat: support preload for documents with non paged representations#1604

Merged
shahzadaziz merged 5 commits intobox:masterfrom
shahzadaziz:small-docs
Feb 9, 2026
Merged

feat: support preload for documents with non paged representations#1604
shahzadaziz merged 5 commits intobox:masterfrom
shahzadaziz:small-docs

Conversation

@shahzadaziz
Copy link
Copy Markdown
Collaborator

Summary

Introduces showPreloadSingleImage method to support preloading small documents (<5MB) that have non-paged JPEG representations instead of paged WebP. The feature is gated by a new showPreloadForNonPaged config flag to allow controlled rollout.

Key Changes

  • New method showPreloadSingleImage: Handles preload for documents with single-image (non-paged) representations
    Config-gated feature: Added config.showPreloadForNonPaged check in showPreload() - when disabled, falls back to showing preview mask
  • DocBaseViewer updates: Extended preload logic to handle non-paged representation path when docFirstPagesEnabled is true
  • Asset loading: Updated docAssets.js to support EXIF reader for non-paged preloads
  • Tests: Added comprehensive test coverage for the new showPreloadSingleImage method and config flag behavior

@shahzadaziz shahzadaziz requested a review from a team as a code owner January 30, 2026 23:01
} else if (pagedPreLoadUrlWithAuth) {
await this.showPreloadAll(preloadUrlWithAuth, pagedPreLoadUrlWithAuth, pages, docBaseViewer);
} else if (preloadUrlWithAuth && this.config.showPreloadForNonPaged) {
await this.showPreloadSingleImage(preloadUrlWithAuth, pages, docBaseViewer);
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduce new preload path for non-paged reps. Appllies to JPEG reps for documents <5mb

Comment thread src/lib/viewers/doc/DocBaseViewer.js Outdated
);
Promise.all(remainingPromises);
}, secondBatchDelayMs);
if (secondBatchDelayMs) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would happen if prefetchPriorityPagesOnly is set to true and secondBatchDelayMs is set to 0. It might not be a configuration that we would set by design. But it would be safer to detect that case and add a default secondBatchDelay here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call . I will update this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok i see what you were trying to suggest. prefetchPriorityPagesOnly would lead to an early return

if (prefetchPriorityPagesOnly) {
                        return;

The prefetchPriorityPagesOnly = false and 0 is the problem. I think we might not need this check here tbh.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up removing this check since we would still want the setTimeout to run. 0 ends up triggering immediately which is desired outcome.

Copy link
Copy Markdown
Collaborator

@sanilsalvi sanilsalvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@shahzadaziz shahzadaziz merged commit 4e0bd75 into box:master Feb 9, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants