Skip to content

Commit

Permalink
Fix critical / non-critial JS path comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
jkphl committed Jan 12, 2019
1 parent d2f1f21 commit 520403c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 1.0.1 Bugfix release (2018-01-12)
* Fix critical / non-critial JS path comparison

## 1.0.0 Feature release (2018-01-12)
* Prevent double evaluation of critical JavaScripts on first load ([#2](https://github.com/jkphl/shortbread/issues/2)))
* Prevent double evaluation of critical JavaScripts on first load ([#2](https://github.com/jkphl/shortbread/issues/2))
* Remove Filament Group's loadCSS
* Switch to [jkphl/prelink](https://github.com/jkphl/prelink)

Expand Down
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function shortbread(js, css, critical, slot, callback, config) {
const cssFiles = makeVinylFileList(css);
const cssUrls = makeUrlList(css);
const criticalFiles = makeVinylFileList(critical);
const criticalFilePaths = criticalFiles.map(criticalFile => criticalFile.path);
const criticalFilePaths = criticalFiles.map(criticalFile => path.resolve(criticalFile.path));
const cookieSlot = (typeof slot === 'string') ? (slot.trim() || null) : null;
const options = Object.assign({
prefix: '',
Expand Down Expand Up @@ -148,12 +148,11 @@ function shortbread(js, css, critical, slot, callback, config) {

// 1. JavaScript resources
jsFiles.forEach((jsFile) => {
// console.log(jsFile.path);
const resourceHash = shortbread.createHash(jsFile.contents.toString());
result.resources[resourceHash] = `${options.prefix}${jsFile.relative}`;

// If this resource is also registered as critical JavaScript
if (criticalFilePaths.indexOf(jsFile.path) >= 0) {
if (criticalFilePaths.indexOf(path.resolve(jsFile.path)) >= 0) {
needsPrelink = true;
clientResources[resourceHash] = 0;
result.initial += `<link rel="prefetch" href="${result.resources[resourceHash]}" id="${resourceHash}" as="script" onload="SHORTBREAD_INSTANCE.onloadScript(this)">`;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "shortbread",
"version": "1.0.0",
"version": "1.0.1",
"description": "Asynchronous, non-blocking loading pattern for CSS and JavaScript resources",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 520403c

Please sign in to comment.