diff --git a/packages/optimizer/lib/fetchRuntimeParameters.js b/packages/optimizer/lib/fetchRuntimeParameters.js index 54895e7f8..a3d1f5d93 100644 --- a/packages/optimizer/lib/fetchRuntimeParameters.js +++ b/packages/optimizer/lib/fetchRuntimeParameters.js @@ -79,8 +79,8 @@ async function fetchValidatorRules_(config) { let rawRules = await cache.get('validator-rules'); let validatorRules; if (!rawRules) { - config.log.debug('Downloading AMP validation rules'); validatorRules = await validatorRulesProvider.fetch(); + config.log.debug('Downloaded AMP validation rules'); // We save the raw rules to make the validation rules JSON serializable cache.set(KEY_VALIDATOR_RULES, validatorRules.raw); } else { @@ -136,8 +136,8 @@ async function fetchAmpRuntimeVersion_(context) { const versionKey = context.ampUrlPrefix + '-' + context.lts; let ampRuntimeData = await cache.get(versionKey); if (!ampRuntimeData) { - context.config.log.debug('Downloading AMP runtime version'); ampRuntimeData = await fetchLatestRuntimeData_(context, versionKey); + context.config.log.debug('Downloaded AMP runtime v' + ampRuntimeData.version); } else if (MaxAge.fromObject(ampRuntimeData.maxAge).isExpired()) { // return the cached version, but update the cache in the background fetchLatestRuntimeData_(versionKey, context); @@ -197,12 +197,12 @@ async function downloadAmpRuntimeStyles_(config, runtimeCssUrl) { styles = await cache.get(runtimeCssUrl); } if (!styles) { - config.log.debug(`Downloading AMP runtime styles from ${runtimeCssUrl}`); const response = await config.fetch(runtimeCssUrl); if (!response.ok) { return null; } styles = await response.text(); + config.log.debug(`Downloaded AMP runtime styles from ${runtimeCssUrl}`); if (config.cache !== false) { cache.set(runtimeCssUrl, styles); } diff --git a/packages/optimizer/lib/transformers/PreloadHeroImage.js b/packages/optimizer/lib/transformers/PreloadHeroImage.js index 30dc0c436..67e6efb8b 100644 --- a/packages/optimizer/lib/transformers/PreloadHeroImage.js +++ b/packages/optimizer/lib/transformers/PreloadHeroImage.js @@ -35,7 +35,6 @@ class PreloadHeroImage { constructor(config) { this.log = config.log; this.enabled = config.preloadHeroImage !== false && config.experimentPreloadHeroImage; - this.log.info('enabled', this.enabled); } async transform(root, params) { if (!this.enabled || params.preloadHeroImage === false) { diff --git a/packages/optimizer/lib/warmup.js b/packages/optimizer/lib/warmup.js new file mode 100644 index 000000000..22a3f9ec0 --- /dev/null +++ b/packages/optimizer/lib/warmup.js @@ -0,0 +1,28 @@ +/** + * Copyright 2020 The AMP HTML Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const AmpOptimizer = require('../'); +const ampOptimizer = AmpOptimizer.create(); + +async function warmupCaches() { + // run a dummy transformation to pre-fill the caches + await ampOptimizer.transformHtml('

hello world

', { + canonical: '.', + }); + ampOptimizer.config.log.info('Downloading latest AMP runtime data'); +} + +warmupCaches(); diff --git a/packages/optimizer/package.json b/packages/optimizer/package.json index 381546b52..865f8a744 100644 --- a/packages/optimizer/package.json +++ b/packages/optimizer/package.json @@ -9,12 +9,11 @@ "directory": "packages/optimizer" }, "scripts": { - "postinstall": "scripts/init.js" + "postinstall": "node lib/warmup.js" }, "files": [ "index.js", - "lib", - "scripts" + "lib" ], "keywords": [ "amp" diff --git a/packages/optimizer/scripts/init.js b/packages/optimizer/scripts/init.js deleted file mode 100755 index ff25ed7c5..000000000 --- a/packages/optimizer/scripts/init.js +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env node -const AmpOptimizer = require('../'); -const ampOptimizer = AmpOptimizer.create(); - -async function warmupCaches() { - // run a dummy transformation to pre-fill the caches - ampOptimizer.transformHtml('

hello world

', { - canonical: '.', - verbose: true, - }); -} - -warmupCaches();