@divriots/jampack 0.30.1 → 0.30.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config-fast.js +1 -0
- package/dist/optimize.js +7 -5
- package/package.json +1 -1
package/dist/config-fast.js
CHANGED
package/dist/optimize.js
CHANGED
|
@@ -41,7 +41,7 @@ async function analyse(state, file) {
|
|
|
41
41
|
const imgElement = imgsArray[i];
|
|
42
42
|
spinnerImg.text = kleur.dim(`<img> [${i + 1}/${imgsArray.length}] ${$(imgElement).attr('src')}`);
|
|
43
43
|
const img = $(imgElement);
|
|
44
|
-
const isAboveTheFold =
|
|
44
|
+
const isAboveTheFold = isElementAboveTheFold(img, imgElement, theFold);
|
|
45
45
|
img.removeAttr(ABOVE_FOLD_DATA_ATTR);
|
|
46
46
|
try {
|
|
47
47
|
await processImage(state, file, img, isAboveTheFold);
|
|
@@ -75,7 +75,9 @@ async function analyse(state, file) {
|
|
|
75
75
|
for (let i = 0; i < iframesArray.length; i++) {
|
|
76
76
|
const ifElement = iframesArray[i];
|
|
77
77
|
spinnerIframe.text = kleur.dim(`<iframe> [${i + 1}/${iframesArray.length}] ${$(ifElement).attr('src')}`);
|
|
78
|
-
const
|
|
78
|
+
const ifr = $(ifElement);
|
|
79
|
+
const isAboveTheFold = isElementAboveTheFold(ifr, ifElement, theFold);
|
|
80
|
+
ifr.removeAttr(ABOVE_FOLD_DATA_ATTR);
|
|
79
81
|
try {
|
|
80
82
|
await processIframe(file, $, ifElement, isAboveTheFold);
|
|
81
83
|
}
|
|
@@ -167,14 +169,14 @@ async function analyse(state, file) {
|
|
|
167
169
|
await fs.writeFile(path.join(state.dir, file), htmlResult);
|
|
168
170
|
}
|
|
169
171
|
}
|
|
170
|
-
function
|
|
171
|
-
const aboveTheFoldAttr =
|
|
172
|
+
function isElementAboveTheFold(cheerio, element, theFold) {
|
|
173
|
+
const aboveTheFoldAttr = cheerio.attr(ABOVE_FOLD_DATA_ATTR);
|
|
172
174
|
if (aboveTheFoldAttr) {
|
|
173
175
|
const parsed = parseInt(aboveTheFoldAttr);
|
|
174
176
|
if (!Number.isNaN(parsed))
|
|
175
177
|
return !!parsed;
|
|
176
178
|
}
|
|
177
|
-
return
|
|
179
|
+
return element.startIndex < theFold;
|
|
178
180
|
}
|
|
179
181
|
function getTheFold($) {
|
|
180
182
|
const theFolds = $('the-fold');
|