Skip to content

Commit

Permalink
chore(viewer): Enable GZIP for users in the US (#1082)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingze authored and mergify[bot] committed Oct 8, 2019
1 parent 5011b81 commit e7a427d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
6 changes: 2 additions & 4 deletions src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,10 +657,8 @@ class DocBaseViewer extends BaseViewer {
// Disable streaming via fetch until performance is improved
const disableStream = true;

// Disable range requests for files smaller than MINIMUM_RANGE_REQUEST_FILE_SIZE (25MB) for
// previews outside of the US since the additional latency overhead per range request can be
// more than the additional time for a continuous request.
const isRangeSupported = location.locale === 'en-US' || size >= RANGE_REQUEST_MINIMUM_SIZE;
// Disable range requests for files smaller than MINIMUM_RANGE_REQUEST_FILE_SIZE (25MB)
const isRangeSupported = size >= RANGE_REQUEST_MINIMUM_SIZE;
const isWatermarked = watermarkInfo && watermarkInfo.is_watermarked;
const disableRange = isWatermarked || !isRangeSupported;

Expand Down
14 changes: 2 additions & 12 deletions src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1146,18 +1146,16 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
});
});

it('should enable range requests if locale is not en-US, the file is greater than 25MB', () => {
it('should enable range requests if the file is greater than 25MB', () => {
docBase.options.file.size = 26500000;
docBase.options.location.locale = 'ja-JP';

return docBase.initViewer('').then(() => {
expect(stubs.getDocument).to.be.calledWith(sinon.match({ disableRange: false }));
});
});

it('should disable range requests if locale is not en-US and the file is smaller than 25MB', () => {
it('should disable range requests if the file is smaller than 25MB', () => {
docBase.options.file.size = 26000000;
docBase.options.location.locale = 'ja-JP';

return docBase.initViewer('').then(() => {
expect(stubs.getDocument).to.be.calledWith(sinon.match({ disableRange: true }));
Expand All @@ -1174,14 +1172,6 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
});
});

it('should not disable range requests if the locale is en-US', () => {
docBase.options.location.locale = 'en-US';

return docBase.initViewer('').then(() => {
expect(stubs.getDocument).to.be.calledWith(sinon.match({ disableRange: false }));
});
});

it('should set disableCreateObjectURL to false', () => {
return docBase.initViewer('').then(() => {
expect(stubs.getDocument).to.be.calledWith(sinon.match({ disableCreateObjectURL: false }));
Expand Down

0 comments on commit e7a427d

Please sign in to comment.