From 4b29c210bac730ea172cd56109da5278ee770306 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sat, 8 May 2021 18:05:35 -0500 Subject: [PATCH] Try caching inline assets with js Map --- .eleventy.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.eleventy.js b/.eleventy.js index bcdf12e..9af5159 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -14,6 +14,8 @@ function getAssetFilePath(componentName) { return `./${componentName}` } +const inlineAssetCache = new Map() + module.exports = function ( eleventyConfig ) { // console.log('eleventyConfig', eleventyConfig) @@ -31,13 +33,25 @@ module.exports = function ( eleventyConfig ) { const assetFileName = getAssetFilePath( componentName ) + // console.log('Cache size', inlineAssetCache) + if ( componentName.includes('.js') ) { // If a never before seen component, add the JS code - if(!jsManager.hasComponentCode(componentName)) { + if( !inlineAssetCache.has( assetFileName ) ) { let contents = '' + // if ( inlineAssetCache.has( assetFileName ) ) { + // console.log('Reading component from cache', componentName) + // console.log('Cache size', inlineAssetCache.size) + + // contents = inlineAssetCache.get( assetFileName ) + + // } else { + + // } + console.log('Reading component file', componentName) const javascriptCode = fs.readFileSync( assetFileName, { encoding: "UTF-8" }) @@ -46,6 +60,8 @@ module.exports = function ( eleventyConfig ) { contents = minified.code + inlineAssetCache.set( assetFileName, contents ) + // console.log('Got component', componentName, componentCss) jsManager.addComponentCode(componentName, contents)