Skip to content

Commit 693a02d

Browse files
authored
Merge pull request #1174 from basics/next
update
2 parents d8ea2f6 + 0435124 commit 693a02d

File tree

11 files changed

+50
-69
lines changed

11 files changed

+50
-69
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Project Changelog
22

3+
## [3.1.7-next.2](https://github.com/basics/nuxt-booster/compare/v3.1.7-next.1...v3.1.7-next.2) (2024-12-16)
4+
5+
6+
### Bug Fixes
7+
8+
* **entry:** added timeout for video check ([8ae386a](https://github.com/basics/nuxt-booster/commit/8ae386a2992ab94f3dd2a840ae6b9223ea70bd4a))
9+
* **entry:** update visiblity check ([962bf07](https://github.com/basics/nuxt-booster/commit/962bf073be5162cbade22e7eb5f9e5734ed17889))
10+
11+
## [3.1.7-next.1](https://github.com/basics/nuxt-booster/compare/v3.1.6...v3.1.7-next.1) (2024-11-01)
12+
13+
14+
### Bug Fixes
15+
16+
* **node-cache:** removed `node-cache` ([a3afce2](https://github.com/basics/nuxt-booster/commit/a3afce206b74d278a785a757b773b2644e0147e4))
17+
318
## [3.1.6](https://github.com/basics/nuxt-booster/compare/v3.1.5...v3.1.6) (2024-09-17)
419

520

build.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export default {
66
'change-case',
77
'hash-sum',
88
'probe-image-size',
9-
'node-cache',
109

1110
// package
1211
'@nuxt/image',

docs/src/guide/options.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -274,22 +274,6 @@ Global option for the [`IntersectionObserver`](https://developer.mozilla.org/en-
274274
| `component` | `String` | yes | [`rootMargin`](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/rootMargin) value for [`BoosterHydrate`](/guide/usage#import-components). | `0%` |
275275
| `asset` | `String` | yes | [`rootMargin`](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/rootMargin) value for all static ressources (`v-font`, `BoosterPicture` & `BoosterImage`). | `0%` |
276276

277-
## `imageSizeCache`
278-
279-
- Type: `Object`
280-
- Default: `{ stdTTL: 3600, checkperiod: 1800 }`
281-
282-
The `imageSizeCache` option is used to cache the image sizes of the `BoosterImage` and `BoosterPicture` components. This reduces the number of requests to the server and speeds up the loading process.
283-
284-
Learn more about the options in the [node-cache documentation](https://www.npmjs.com/package/node-cache#options).
285-
286-
````js
287-
{
288-
stdTTL: 3600,
289-
checkperiod: 1800
290-
}
291-
````
292-
293277
## `disableNuxtFontaine`
294278

295279
- Type: `Boolean`

package-lock.json

Lines changed: 2 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nuxt-booster",
3-
"version": "3.1.6",
3+
"version": "3.1.7-next.2",
44
"description": "Nuxt Booster takes over the Lighthouse performance optimization of your generated website.",
55
"license": "MIT",
66
"author": "Stephan Gerbeth",
@@ -61,7 +61,6 @@
6161
"htmlparser2": "9.1.0",
6262
"image-meta": "0.2.1",
6363
"mime-types": "2.1.35",
64-
"node-cache": "5.1.2",
6564
"pathe": "1.1.2",
6665
"sort-css-media-queries": "2.4.0"
6766
},

src/module.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ async function addBuildTemplates(nuxt, options) {
120120
targetFormats: options.targetFormats,
121121
crossorigin: getCrossorigin(options.crossorigin),
122122
supportedBrowserDetector,
123-
loader: options.loader,
124-
imageSizeCache: options.imageSizeCache
123+
loader: options.loader
125124
});
126125
},
127126
filename: MODULE_NAME + `/plugin.${mode}.js`,

src/runtime/utils/entry.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ export const hasBatteryPerformanceIssue = async videoBlob => {
7272
}
7373
};
7474

75+
export const waitForVisibilty = () => {
76+
const { promise, resolve } = Promise.withResolvers();
77+
if (document.visibilityState === 'hidden') {
78+
document.addEventListener('visibilitychange', resolve, {
79+
once: true
80+
});
81+
} else {
82+
resolve();
83+
}
84+
return promise;
85+
};
86+
7587
/**
7688
* Checks if battery still has enough energy.
7789
* This check is for Chrome and all other browsers that support this setting.
@@ -99,7 +111,13 @@ export const canVideoPlay = async blob => {
99111
video.muted = true;
100112
video.playsinline = true;
101113
video.src = objectUrl;
102-
await video.play();
114+
115+
const { resolve, promise } = Promise.withResolvers();
116+
const timeout = window.setTimeout(resolve, 500);
117+
118+
await Promise.race([video.play(), promise]);
119+
window.clearTimeout(timeout);
120+
103121
URL.revokeObjectURL(objectUrl);
104122
} catch (error) {
105123
URL.revokeObjectURL(objectUrl);

src/runtime/utils/performance.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,8 @@ export const getDefaultRunOptions = () => {
7272
return { maxTime: 1000, threshold: 0.65 };
7373
};
7474

75-
export const waitForVisibleDocument = () => {
76-
return new Promise(resolve => {
77-
if (document.visibilityState === 'hidden') {
78-
document.addEventListener('visibilitychange', () => resolve(), {
79-
once: true
80-
});
81-
} else {
82-
resolve();
83-
}
84-
});
85-
};
86-
8775
export const run = async (options = {}) => {
8876
if (window.requestIdleCallback) {
89-
await waitForVisibleDocument();
90-
9177
const { maxTime, threshold } = { ...getDefaultRunOptions(), ...options };
9278
const fpsObserver = new CallbackObserver(rafTime);
9379
const idleObserver = new CallbackObserver(idleTime);

src/tmpl/entry.tmpl.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export default options => {
22
let code = `import { ${
33
options.performanceCheck ? `run, ` : ``
44
}hasSufficientPerformance, setup } from '#booster/utils/performance';
5-
import { triggerRunCallback, observeBoosterButton, setupBoosterLayer, updateBoosterLayerMessage, initReducedView, hasBatteryPerformanceIssue, deprecationWarningButtonSelector } from '#booster/utils/entry';
5+
import { waitForVisibilty, triggerRunCallback, observeBoosterButton, setupBoosterLayer, updateBoosterLayerMessage, initReducedView, hasBatteryPerformanceIssue, deprecationWarningButtonSelector } from '#booster/utils/entry';
66
import Deferred from '#booster/classes/Deferred';
77
import { isSupportedBrowser } from '#booster/utils/browser';
88
import {video as videoBlob} from './blobs.mjs';
@@ -52,6 +52,8 @@ function client () {
5252
deferred.resolve();
5353
}
5454
55+
await waitForVisibilty();
56+
5557
document.documentElement.classList.remove('nuxt-booster-reduced-view');
5658
5759
`;

src/tmpl/plugin.tmpl.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ import FontList from '#booster/classes/FontList';
66
import { useNuxtApp, useBoosterHead, useRequestHeaders, useRequestURL, useRequestFetch } from '#imports';
77
import './fonts.css';`;
88

9-
if (options.mode !== 'client') {
10-
code += `
11-
import NodeCache from 'node-cache';
12-
`;
13-
}
14-
159
code += `
1610
1711
export default defineNuxtPlugin({
@@ -54,15 +48,9 @@ export default defineNuxtPlugin({
5448
5549
`;
5650

57-
if (options.mode === 'client') {
58-
code += `
59-
const dimensionCache = new Map();`;
60-
} else {
61-
code += `
62-
const dimensionCache = new NodeCache({ useClones: false, ...${JSON.stringify(options.imageSizeCache)} });`;
63-
}
64-
6551
code += `
52+
const dimensionCache = new Map();
53+
6654
async function getImageSize (src) {
6755
`;
6856

0 commit comments

Comments
 (0)