Skip to content

Commit

Permalink
🐛 Bust cached document for amp-addthis (#26761)
Browse files Browse the repository at this point in the history
Adds ?_amp_=VERSION query param to bust broken versions of document when cached
(origin has overly long max-age of 999 days, workaround for #24848)
  • Loading branch information
alanorozco authored Feb 12, 2020
1 parent 4ad2a25 commit 9425558
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 5 additions & 2 deletions extensions/amp-addthis/0.1/amp-addthis.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import {DwellMonitor} from './addthis-utils/monitors/dwell-monitor';
import {PostMessageDispatcher} from './post-message-dispatcher';
import {ScrollMonitor} from './addthis-utils/monitors/scroll-monitor';
import {Services} from '../../../src/services';

import {callEng} from './addthis-utils/eng';
import {callLojson} from './addthis-utils/lojson';
import {callPjson} from './addthis-utils/pjson';
Expand All @@ -66,6 +65,7 @@ import {
} from './addthis-utils/mode';
import {getOgImage} from './addthis-utils/meta';
import {getWidgetOverload} from './addthis-utils/get-widget-id-overloaded-with-json-for-anonymous-mode';
import {internalRuntimeVersion} from '../../../src/internal-version';
import {isLayoutSizeDefined} from '../../../src/layout';
import {listen} from '../../../src/event-helper';
import {parseUrlDeprecated} from '../../../src/url';
Expand Down Expand Up @@ -299,7 +299,10 @@ class AmpAddThis extends AMP.BaseElement {
dict({
'frameborder': 0,
'title': ALT_TEXT,
'src': `${ORIGIN}/dc/amp-addthis.html`,
// Document has overly long cache age: go.amp.dev/issue/24848
// Adding AMP runtime version as a meaningless query param to force bust
// cached versions.
'src': `${ORIGIN}/dc/amp-addthis.html?_amp_=${internalRuntimeVersion()}`,
'id': this.widgetId_,
'pco': this.productCode_,
'containerClassName': this.containerClassName_,
Expand Down
9 changes: 6 additions & 3 deletions extensions/amp-addthis/0.1/test/test-amp-addthis.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {getDetailsForMeta, getMetaElements} from './../addthis-utils/meta';
import {getKeywordsString} from './../addthis-utils/classify';
import {getSessionId} from '../addthis-utils/session';
import {getWidgetOverload} from '../addthis-utils/get-widget-id-overloaded-with-json-for-anonymous-mode';
import {startsWith} from '../../../../src/string';
import {toArray} from '../../../../src/types';

describes.realWin(
Expand Down Expand Up @@ -101,9 +102,11 @@ describes.realWin(

function testIframe(iframe) {
expect(iframe).to.not.equal(null);
expect(iframe.getAttribute('src')).to.equal(
`${ORIGIN}/dc/amp-addthis.html`
);
const srcPrefix = `${ORIGIN}/dc/amp-addthis.html?`;
expect(
startsWith(iframe.getAttribute('src'), srcPrefix),
`iframe src starts with ${srcPrefix}`
).to.be.true;
expect(iframe.getAttribute('title')).to.equal(ALT_TEXT);
}

Expand Down

0 comments on commit 9425558

Please sign in to comment.