1
- # Nuxt HTTP Client Hints
1
+ # Nuxt HTTP Client Hints Module
2
2
3
3
[ ![ npm version] [ npm-version-src ]] [ npm-version-href ]
4
4
[ ![ npm downloads] [ npm-downloads-src ]] [ npm-downloads-href ]
5
5
[ ![ License] [ license-src ]] [ license-href ]
6
6
[ ![ Nuxt] [ nuxt-src ]] [ nuxt-href ]
7
7
8
- My new Nuxt module for doing amazing things.
9
-
10
- - [ ✨   ; Release Notes] ( /CHANGELOG.md )
11
- <!-- - [🏀 Online playground](https://stackblitz.com/github/your-org/my-module?file=playground%2Fapp.vue) -->
12
- <!-- - [📖 Documentation](https://example.com) -->
8
+ Access and use HTTP Client Hints in your Nuxt application. Detect the client browser and the operating system on your server.
13
9
14
10
## Features
15
11
16
- <!-- Highlight some of the features your module provide here -->
17
- - ⛰   ; Foo
18
- - 🚠   ; Bar
19
- - 🌲   ; Baz
12
+ - 🚀 Browser and Operating System detection: check [ detect-browser-es] ( https://www.npmjs.com/package/detect-browser-es ) for more information.
13
+ - 💥 [ Device Hints] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers#client_hints ) detection
14
+ - ⚡ [ Network Hints] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers#client_hints ) detection
15
+ - ✨ [ Critical Hints] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Client_hints#critical_client_hints ) detection
16
+
17
+ ## HTTP Client hints
18
+
19
+ > [ !WARNING]
20
+ > The [ HTTP Client hints headers] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Client_hints ) listed below are still in draft and only Chromium based browsers support them: Chrome, Edge, Chromium and Opera.
21
+
22
+
23
+ The module includes support for the following HTTP Client hints:
24
+ - [ Device Hints] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers#client_hints )
25
+ - [ Device-Memory] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Device-Memory )
26
+ - [ Network Hints] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers#client_hints )
27
+ - [ Save-Data] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Save-Data )
28
+ - [ Downlink] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Downlink )
29
+ - [ ECT] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ECT )
30
+ - [ RTT] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/RTT )
31
+ - [ User Agent Hints] ( https://github.com/WICG/ua-client-hints )
32
+ - [ Sec-CH] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH )
33
+ - [ Sec-CH-UA] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-UA )
34
+ - [ Sec-CH-UA-Mobile] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-UA-Mobile )
35
+ - [ Sec-CH-UA-Platform] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-UA-Platform )
36
+ - [ Sec-CH-UA-Arch] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-UA-Arch )
37
+ - [ Sec-CH-UA-Model] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-UA-Model )
38
+ - [ Sec-CH-UA-Platform-Version] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-UA-Platform-Version )
39
+ - [ Sec-CH-UA-Bitness] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-UA-Bitness )
40
+ - [ Critical Client Hints] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Client_hints#critical_client_hints )
41
+ - [ Sec-CH-Width] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-Width )
42
+ - [ Sec-CH-DPR] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-DPR )
43
+ - [ Sec-CH-Viewport-Width] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-Viewport-Width )
44
+ - [ Sec-CH-Viewport-Height] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-Viewport-Height )
45
+ - [ Sec-CH-Prefers-Color-Scheme] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-Prefers-Color-Scheme )
46
+ - [ Sec-CH-Prefers-Reduced-Motion] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-Prefers-Reduced-Motion )
47
+ - [ Sec-CH-Prefers-Reduced-Transparency] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-Prefers-Reduced-Transparency )
48
+
20
49
21
50
## Quick Setup
22
51
23
52
Install the module to your Nuxt application with one command:
24
53
25
54
``` bash
26
- npx nuxi module add my-module
55
+ npx nuxi module add nuxt-http-client-hints
56
+ ```
57
+
58
+ Add your configuration to your Nuxt config file:
59
+
60
+ ``` js
61
+ httpClientHints: {
62
+ // Your configuration here
63
+ }
64
+ ```
65
+
66
+ Add your client and server plugins to your Nuxt application and register the corresponding hooks with your configuration:
67
+
68
+ ``` js
69
+ // my-plugin.client.js
70
+ export default defineNuxtPlugin ((nuxtApp ) => {
71
+ nuxtApp .hook (' http-client-hints:client-hints' , (httpClientHints ) => {
72
+ // Your client logic here
73
+ })
74
+ })
75
+ ```
76
+
77
+ ``` js
78
+ // my-plugin.server.js
79
+ export default defineNuxtPlugin ((nuxtApp ) => {
80
+ nuxtApp .hook (' http-client-hints:ssr-client-hints' , (httpClientHints ) => {
81
+ // Your server logic here
82
+ })
83
+ })
84
+ ```
85
+
86
+ You use the httpClientHints object in your application to access the configuration:
87
+
88
+ ``` html
89
+ <!-- SomeComponent.vue -->
90
+ <template >
91
+ <pre >{{ $httpClientHints }}"</pre >
92
+ </template >
93
+ ```
94
+
95
+ or in your modules:
96
+ ``` js
97
+ // my-module.js
98
+ const clientHints = useNuxtApp ().$httpClientHints
27
99
```
28
100
29
101
That's it! You can now use HTTP Client Hints in your Nuxt app ✨
30
102
103
+ You can check the source code or the [ JSDocs] ( https://www.jsdocs.io/package/nuxt-http-client-hints ) for more information.
31
104
32
105
## Contribution
33
106
@@ -36,40 +109,42 @@ That's it! You can now use HTTP Client Hints in your Nuxt app ✨
36
109
37
110
``` bash
38
111
# Install dependencies
39
- npm install
112
+ pnpm install
40
113
41
114
# Generate type stubs
42
- npm run dev:prepare
115
+ pnpm run dev:prepare
43
116
44
117
# Develop with the playground
45
- npm run dev
118
+ pnpm run dev
46
119
47
120
# Build the playground
48
- npm run dev:build
121
+ pnpm run dev:build
49
122
50
123
# Run ESLint
51
- npm run lint
124
+ pnpm run lint
52
125
53
126
# Run Vitest
54
- npm run test
55
- npm run test:watch
56
-
57
- # Release new version
58
- npm run release
127
+ pnpm run test
128
+ pnpm run test:watch
59
129
```
60
130
61
131
</details >
62
132
63
133
64
- <!-- Badges -->
65
- [ npm-version-src ] : https://img.shields.io/npm/v/my-module/latest.svg?style=flat&colorA=020420&colorB=00DC82
66
- [ npm-version-href ] : https://npmjs.com/package/my-module
134
+ ## License
67
135
68
- [ npm-downloads-src ] : https://img.shields.io/npm/dm/my-module.svg?style=flat&colorA=020420&colorB=00DC82
69
- [ npm-downloads-href ] : https://npmjs.com/package/my-module
136
+ [ MIT] ( ./LICENSE ) License © 2024-PRESENT [ Joaquín Sánchez] ( https://github.com/userquin )
70
137
71
- [ license-src ] : https://img.shields.io/npm/l/my-module.svg?style=flat&colorA=020420&colorB=00DC82
72
- [ license-href ] : https://npmjs.com/package/my-module
138
+ <!-- Badges -->
73
139
140
+ [ npm-version-src ] : https://img.shields.io/npm/v/nuxt-http-client-hints?style=flat&colorA=18181B&colorB=F0DB4F
141
+ [ npm-version-href ] : https://npmjs.com/package/nuxt-http-client-hints
142
+ [ npm-downloads-src ] : https://img.shields.io/npm/dm/nuxt-http-client-hints?style=flat&colorA=18181B&colorB=F0DB4F
143
+ [ npm-downloads-href ] : https://npmjs.com/package/nuxt-http-client-hints
144
+ [ jsdocs-src ] : https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=18181B&colorB=F0DB4F
145
+ [ jsdocs-href ] : https://www.jsdocs.io/package/nuxt-http-client-hints
146
+ [ license-src ] : https://img.shields.io/github/license/userquin/nuxt-http-client-hints.svg?style=flat&colorA=18181B&colorB=F0DB4F
147
+ [ license-href ] : https://github.com/userquin/nuxt-http-client-hints/blob/main/LICENSE
74
148
[ nuxt-src ] : https://img.shields.io/badge/Nuxt-020420?logo=nuxt.js
75
149
[ nuxt-href ] : https://nuxt.com
150
+
0 commit comments