Skip to content

Commit a91b7c2

Browse files
committed
Compile template only once
1 parent 462f5f2 commit a91b7c2

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

Lesson03/exercise_004/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ console.log(`Loaded ${products.length} products...`);
1414

1515
handlebars.registerHelper('currency', (number) => `$${number.toFixed(2)}`);
1616

17-
const htmlTemplate = fs.readFileSync('html/index.html').toString();
17+
const htmlString = fs.readFileSync('html/index.html').toString();
18+
const template = handlebars.compile(htmlString);
1819
function handleProductsPage(requestUrl, response) {
19-
const template = handlebars.compile(htmlTemplate);
20-
2120
response.writeHead(200);
2221
response.write(template({ products: products }));
2322
response.end();

0 commit comments

Comments
 (0)