diff --git a/build-system/test-configs/dep-check-config.js b/build-system/test-configs/dep-check-config.js index 17fda23c5a82..9d51fa5c6bf8 100644 --- a/build-system/test-configs/dep-check-config.js +++ b/build-system/test-configs/dep-check-config.js @@ -392,6 +392,8 @@ exports.rules = [ 'src/service/origin-experiments-impl.js', 'extensions/amp-script/0.1/amp-script.js->' + 'src/service/origin-experiments-impl.js', + 'extensions/amp-live-list/0.1/live-list-manager.js->' + + 'src/service/origin-experiments-impl.js', // For action macros. 'extensions/amp-action-macro/0.1/amp-action-macro.js->' + 'src/service/action-impl.js', diff --git a/extensions/amp-live-list/0.1/live-list-manager.js b/extensions/amp-live-list/0.1/live-list-manager.js index e1c34f352595..9250bec4cf0b 100644 --- a/extensions/amp-live-list/0.1/live-list-manager.js +++ b/extensions/amp-live-list/0.1/live-list-manager.js @@ -16,10 +16,15 @@ import {Poller} from './poller'; import {Services} from '../../../src/services'; -import {addParamToUrl} from '../../../src/url'; +import {addParamsToUrl} from '../../../src/url'; +import {dict} from '../../../src/utils/object'; import {fetchDocument} from '../../../src/document-fetcher'; import {getMode} from '../../../src/mode'; import {getServicePromiseForDoc} from '../../../src/service'; +import { + installOriginExperimentsForDoc, + originExperimentsForDoc, +} from '../../../src/service/origin-experiments-impl'; import {startsWith} from '../../../src/string'; import {toArray} from '../../../src/types'; import {userAssert} from '../../../src/log'; @@ -77,6 +82,9 @@ export class LiveListManager { /** @private @const {boolean} */ this.isTransformed_ = isDocTransformed(ampdoc.getRootNode()); + /** @private {?boolean} */ + this.enrolledInAppendRandomExperiment_ = null; + // Only start polling when doc is ready and when the doc is visible. this.whenDocReady_().then(() => { // Switch out the poller interval if we can find a lower one and @@ -147,11 +155,17 @@ export class LiveListManager { fetchDocument_() { let url = this.url_; if (this.latestUpdateTime_ > 0) { - url = addParamToUrl( - url, - 'amp_latest_update_time', - String(this.latestUpdateTime_) - ); + const parameters = this.enrolledInAppendRandomExperiment_ + ? dict({ + 'amp_latest_update_time': String(this.latestUpdateTime_), + // AMP Caches do not always evict entries from their caches. + // This experiment adds a random identifier to reduce cache hits for enrolled documents. + 'amp_random': String(Math.random()), + }) + : dict({ + 'amp_latest_update_time': String(this.latestUpdateTime_), + }); + url = addParamsToUrl(url, parameters); } if (this.isTransformed_) { @@ -279,6 +293,17 @@ export class LiveListManager { // Polling may not be started yet if no live lists were registered by // doc ready in LiveListManager's constructor. if (liveList.isEnabled() && this.poller_ && this.ampdoc.isVisible()) { + if (this.enrolledInAppendRandomExperiment_ === null) { + // Origin Trial for cache busting requests for `amp-live-list`. + installOriginExperimentsForDoc(this.ampdoc); + originExperimentsForDoc(liveList.element) + .getExperiments() + .then( + trials => + (this.enrolledInAppendRandomExperiment_ = + trials && trials.includes('amp-live-list-random')) + ); + } this.poller_.start(); } }