@wix/site-service-above-the-fold 1.0.6 → 1.0.8
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.
|
@@ -1,10 +1,73 @@
|
|
|
1
1
|
import type { ServiceDefinition } from '@wix/services-definitions';
|
|
2
|
+
/** ID of a component on the page, such as `comp-lxk2h8f1`. */
|
|
2
3
|
export type CompId = string;
|
|
4
|
+
/** Path of a component on the page. */
|
|
3
5
|
export type CompPath = string;
|
|
6
|
+
/** Components the host marks as above the fold or not, keyed by component ID or component path. */
|
|
4
7
|
export type IAboveTheFoldServiceConfig = {
|
|
5
8
|
[key: CompId | CompPath]: boolean;
|
|
6
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Checks whether a component on the current page is above the fold, meaning the page's layout places it
|
|
12
|
+
* in the part of the page shown before a site visitor scrolls.
|
|
13
|
+
*/
|
|
7
14
|
export interface IAboveTheFoldService {
|
|
15
|
+
/**
|
|
16
|
+
* Checks whether a component is above the fold on the current page.
|
|
17
|
+
*
|
|
18
|
+
* Use it to decide what to load or render first, such as loading an image right away when it's
|
|
19
|
+
* above the fold and lazily when it isn't.
|
|
20
|
+
*
|
|
21
|
+
* Returns `undefined` for a component that isn't marked, and never throws. Treat anything other than
|
|
22
|
+
* `true` as not above the fold.
|
|
23
|
+
*
|
|
24
|
+
* The result describes the page's initial layout, not where the site visitor has scrolled to. This
|
|
25
|
+
* value doesn't change for the lifetime of the page. The method does the same lookup while the page
|
|
26
|
+
* renders on the server and in the browser.
|
|
27
|
+
*
|
|
28
|
+
* The result is based on the page's layout, not on the site visitor's screen size, so use it to
|
|
29
|
+
* prioritize loading, not to tell whether a component is visible.
|
|
30
|
+
*
|
|
31
|
+
* @param key Component ID. Case-sensitive, and must match the component's ID exactly.
|
|
32
|
+
* @returns Whether the component is above the fold:
|
|
33
|
+
* - `true`: The host marks the component as above the fold.
|
|
34
|
+
* - `false`: The host marks the component as not above the fold.
|
|
35
|
+
* - `undefined`: The host doesn't mark the component.
|
|
36
|
+
*
|
|
37
|
+
* @exampleValue key 'comp-lxk2h8f1'
|
|
38
|
+
* @exampleValue true
|
|
39
|
+
*
|
|
40
|
+
* @example Load an image right away when it's above the fold
|
|
41
|
+
* ```tsx
|
|
42
|
+
* import { useService } from '@wix/services-manager-react'
|
|
43
|
+
* import { AboveTheFoldDefinition } from '@wix/site-service-above-the-fold/definition'
|
|
44
|
+
*
|
|
45
|
+
* function ProductImage({ id, src, alt }: { id: string; src: string; alt: string }) {
|
|
46
|
+
* const aboveTheFoldService = useService(AboveTheFoldDefinition)
|
|
47
|
+
* const isAboveTheFold = aboveTheFoldService.isInFirstFold(id) === true
|
|
48
|
+
*
|
|
49
|
+
* return (
|
|
50
|
+
* <img
|
|
51
|
+
* id={id}
|
|
52
|
+
* src={src}
|
|
53
|
+
* alt={alt}
|
|
54
|
+
* loading={isAboveTheFold ? 'eager' : 'lazy'}
|
|
55
|
+
* fetchPriority={isAboveTheFold ? 'high' : 'auto'}
|
|
56
|
+
* />
|
|
57
|
+
* )
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @example Preload the images of components above the fold
|
|
62
|
+
* ```ts
|
|
63
|
+
* // aboveTheFoldService is resolved from @wix/site-service-above-the-fold, as in the first example.
|
|
64
|
+
* function imagesToPreload(images: { compId: string; src: string }[]) {
|
|
65
|
+
* return images
|
|
66
|
+
* .filter(({ compId }) => aboveTheFoldService.isInFirstFold(compId) === true)
|
|
67
|
+
* .map(({ src }) => src)
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
8
71
|
isInFirstFold: (key: CompId | CompPath) => boolean | undefined;
|
|
9
72
|
}
|
|
10
73
|
export type IAboveTheFoldDefinition = ServiceDefinition<IAboveTheFoldService, IAboveTheFoldServiceConfig>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/definition/index.ts"],"names":[],"mappings":";;;AAAA,oEAAyD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/definition/index.ts"],"names":[],"mappings":";;;AAAA,oEAAyD;AA+E5C,QAAA,sBAAsB,GAAG,IAAA,oCAAa,EAClD,kCAAkC,CAClC,CAAA"}
|
|
@@ -1,10 +1,73 @@
|
|
|
1
1
|
import type { ServiceDefinition } from '@wix/services-definitions';
|
|
2
|
+
/** ID of a component on the page, such as `comp-lxk2h8f1`. */
|
|
2
3
|
export type CompId = string;
|
|
4
|
+
/** Path of a component on the page. */
|
|
3
5
|
export type CompPath = string;
|
|
6
|
+
/** Components the host marks as above the fold or not, keyed by component ID or component path. */
|
|
4
7
|
export type IAboveTheFoldServiceConfig = {
|
|
5
8
|
[key: CompId | CompPath]: boolean;
|
|
6
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Checks whether a component on the current page is above the fold, meaning the page's layout places it
|
|
12
|
+
* in the part of the page shown before a site visitor scrolls.
|
|
13
|
+
*/
|
|
7
14
|
export interface IAboveTheFoldService {
|
|
15
|
+
/**
|
|
16
|
+
* Checks whether a component is above the fold on the current page.
|
|
17
|
+
*
|
|
18
|
+
* Use it to decide what to load or render first, such as loading an image right away when it's
|
|
19
|
+
* above the fold and lazily when it isn't.
|
|
20
|
+
*
|
|
21
|
+
* Returns `undefined` for a component that isn't marked, and never throws. Treat anything other than
|
|
22
|
+
* `true` as not above the fold.
|
|
23
|
+
*
|
|
24
|
+
* The result describes the page's initial layout, not where the site visitor has scrolled to. This
|
|
25
|
+
* value doesn't change for the lifetime of the page. The method does the same lookup while the page
|
|
26
|
+
* renders on the server and in the browser.
|
|
27
|
+
*
|
|
28
|
+
* The result is based on the page's layout, not on the site visitor's screen size, so use it to
|
|
29
|
+
* prioritize loading, not to tell whether a component is visible.
|
|
30
|
+
*
|
|
31
|
+
* @param key Component ID. Case-sensitive, and must match the component's ID exactly.
|
|
32
|
+
* @returns Whether the component is above the fold:
|
|
33
|
+
* - `true`: The host marks the component as above the fold.
|
|
34
|
+
* - `false`: The host marks the component as not above the fold.
|
|
35
|
+
* - `undefined`: The host doesn't mark the component.
|
|
36
|
+
*
|
|
37
|
+
* @exampleValue key 'comp-lxk2h8f1'
|
|
38
|
+
* @exampleValue true
|
|
39
|
+
*
|
|
40
|
+
* @example Load an image right away when it's above the fold
|
|
41
|
+
* ```tsx
|
|
42
|
+
* import { useService } from '@wix/services-manager-react'
|
|
43
|
+
* import { AboveTheFoldDefinition } from '@wix/site-service-above-the-fold/definition'
|
|
44
|
+
*
|
|
45
|
+
* function ProductImage({ id, src, alt }: { id: string; src: string; alt: string }) {
|
|
46
|
+
* const aboveTheFoldService = useService(AboveTheFoldDefinition)
|
|
47
|
+
* const isAboveTheFold = aboveTheFoldService.isInFirstFold(id) === true
|
|
48
|
+
*
|
|
49
|
+
* return (
|
|
50
|
+
* <img
|
|
51
|
+
* id={id}
|
|
52
|
+
* src={src}
|
|
53
|
+
* alt={alt}
|
|
54
|
+
* loading={isAboveTheFold ? 'eager' : 'lazy'}
|
|
55
|
+
* fetchPriority={isAboveTheFold ? 'high' : 'auto'}
|
|
56
|
+
* />
|
|
57
|
+
* )
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @example Preload the images of components above the fold
|
|
62
|
+
* ```ts
|
|
63
|
+
* // aboveTheFoldService is resolved from @wix/site-service-above-the-fold, as in the first example.
|
|
64
|
+
* function imagesToPreload(images: { compId: string; src: string }[]) {
|
|
65
|
+
* return images
|
|
66
|
+
* .filter(({ compId }) => aboveTheFoldService.isInFirstFold(compId) === true)
|
|
67
|
+
* .map(({ src }) => src)
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
8
71
|
isInFirstFold: (key: CompId | CompPath) => boolean | undefined;
|
|
9
72
|
}
|
|
10
73
|
export type IAboveTheFoldDefinition = ServiceDefinition<IAboveTheFoldService, IAboveTheFoldServiceConfig>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/definition/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/definition/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AA+EzD,MAAM,CAAC,MAAM,sBAAsB,GAAG,aAAa,CAClD,kCAAkC,CAClC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/site-service-above-the-fold",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
]
|
|
78
78
|
}
|
|
79
79
|
},
|
|
80
|
-
"falconPackageHash": "
|
|
80
|
+
"falconPackageHash": "5f828eba1c426bb6c3b6bdc5d7f88c9f7634dab351e26be6cdf4cf5b"
|
|
81
81
|
}
|
package/src/definition/index.ts
CHANGED
|
@@ -1,14 +1,77 @@
|
|
|
1
1
|
import { defineService } from '@wix/services-definitions'
|
|
2
2
|
import type { ServiceDefinition } from '@wix/services-definitions'
|
|
3
3
|
|
|
4
|
+
/** ID of a component on the page, such as `comp-lxk2h8f1`. */
|
|
4
5
|
export type CompId = string
|
|
6
|
+
/** Path of a component on the page. */
|
|
5
7
|
export type CompPath = string
|
|
6
8
|
|
|
9
|
+
/** Components the host marks as above the fold or not, keyed by component ID or component path. */
|
|
7
10
|
export type IAboveTheFoldServiceConfig = {
|
|
8
11
|
[key: CompId | CompPath]: boolean
|
|
9
12
|
}
|
|
10
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Checks whether a component on the current page is above the fold, meaning the page's layout places it
|
|
16
|
+
* in the part of the page shown before a site visitor scrolls.
|
|
17
|
+
*/
|
|
11
18
|
export interface IAboveTheFoldService {
|
|
19
|
+
/**
|
|
20
|
+
* Checks whether a component is above the fold on the current page.
|
|
21
|
+
*
|
|
22
|
+
* Use it to decide what to load or render first, such as loading an image right away when it's
|
|
23
|
+
* above the fold and lazily when it isn't.
|
|
24
|
+
*
|
|
25
|
+
* Returns `undefined` for a component that isn't marked, and never throws. Treat anything other than
|
|
26
|
+
* `true` as not above the fold.
|
|
27
|
+
*
|
|
28
|
+
* The result describes the page's initial layout, not where the site visitor has scrolled to. This
|
|
29
|
+
* value doesn't change for the lifetime of the page. The method does the same lookup while the page
|
|
30
|
+
* renders on the server and in the browser.
|
|
31
|
+
*
|
|
32
|
+
* The result is based on the page's layout, not on the site visitor's screen size, so use it to
|
|
33
|
+
* prioritize loading, not to tell whether a component is visible.
|
|
34
|
+
*
|
|
35
|
+
* @param key Component ID. Case-sensitive, and must match the component's ID exactly.
|
|
36
|
+
* @returns Whether the component is above the fold:
|
|
37
|
+
* - `true`: The host marks the component as above the fold.
|
|
38
|
+
* - `false`: The host marks the component as not above the fold.
|
|
39
|
+
* - `undefined`: The host doesn't mark the component.
|
|
40
|
+
*
|
|
41
|
+
* @exampleValue key 'comp-lxk2h8f1'
|
|
42
|
+
* @exampleValue true
|
|
43
|
+
*
|
|
44
|
+
* @example Load an image right away when it's above the fold
|
|
45
|
+
* ```tsx
|
|
46
|
+
* import { useService } from '@wix/services-manager-react'
|
|
47
|
+
* import { AboveTheFoldDefinition } from '@wix/site-service-above-the-fold/definition'
|
|
48
|
+
*
|
|
49
|
+
* function ProductImage({ id, src, alt }: { id: string; src: string; alt: string }) {
|
|
50
|
+
* const aboveTheFoldService = useService(AboveTheFoldDefinition)
|
|
51
|
+
* const isAboveTheFold = aboveTheFoldService.isInFirstFold(id) === true
|
|
52
|
+
*
|
|
53
|
+
* return (
|
|
54
|
+
* <img
|
|
55
|
+
* id={id}
|
|
56
|
+
* src={src}
|
|
57
|
+
* alt={alt}
|
|
58
|
+
* loading={isAboveTheFold ? 'eager' : 'lazy'}
|
|
59
|
+
* fetchPriority={isAboveTheFold ? 'high' : 'auto'}
|
|
60
|
+
* />
|
|
61
|
+
* )
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @example Preload the images of components above the fold
|
|
66
|
+
* ```ts
|
|
67
|
+
* // aboveTheFoldService is resolved from @wix/site-service-above-the-fold, as in the first example.
|
|
68
|
+
* function imagesToPreload(images: { compId: string; src: string }[]) {
|
|
69
|
+
* return images
|
|
70
|
+
* .filter(({ compId }) => aboveTheFoldService.isInFirstFold(compId) === true)
|
|
71
|
+
* .map(({ src }) => src)
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
12
75
|
isInFirstFold: (key: CompId | CompPath) => boolean | undefined
|
|
13
76
|
}
|
|
14
77
|
|