Skip to content

Commit e445db8

Browse files
authored
chore: various improvements for perf (#2144)
1 parent 92dec4c commit e445db8

File tree

20 files changed

+117
-75
lines changed

20 files changed

+117
-75
lines changed

app/app.vue

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,8 @@ watch(() => colorMode.preference, (newMode, oldMode) => {
1515
})
1616
1717
const [{ data: navigation }, { data: files }] = await Promise.all([
18-
useAsyncData('navigation', () => {
19-
return Promise.all([
20-
queryCollectionNavigation('docsv3', ['titleTemplate']).then(data => data[0]?.children),
21-
queryCollectionNavigation('docsv4', ['titleTemplate']).then(data => data[0]?.children),
22-
queryCollectionNavigation('blog')
23-
])
24-
}, {
25-
transform: data => data.flat(),
26-
watch: [version]
27-
}),
28-
useLazyAsyncData('search', () => {
29-
return Promise.all([
30-
queryCollectionSearchSections('docsv3', { ignoredTags: ['style'] }),
31-
queryCollectionSearchSections('docsv4', { ignoredTags: ['style'] }),
32-
queryCollectionSearchSections('blog')
33-
])
34-
}, {
35-
server: false,
36-
transform: data => data.flat(),
37-
watch: [version]
38-
})
18+
useFetch('/api/navigation.json'),
19+
useFetch('/api/search.json', { server: false })
3920
])
4021
4122
onNuxtReady(() => {

app/error.vue

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,8 @@ const { fetchList: fetchModules } = useModules()
1515
const { fetchList: fetchHosting } = useHostingProviders()
1616
1717
const [{ data: navigation }, { data: files }] = await Promise.all([
18-
useAsyncData('navigation', () => {
19-
return Promise.all([
20-
queryCollectionNavigation('docsv3', ['titleTemplate']),
21-
queryCollectionNavigation('docsv4', ['titleTemplate']).then(data => data[0]?.children),
22-
queryCollectionNavigation('blog')
23-
])
24-
}, {
25-
transform: data => data.flat(),
26-
watch: [version]
27-
}),
28-
useLazyAsyncData('search', () => {
29-
return Promise.all([
30-
queryCollectionSearchSections('docsv3', { ignoredTags: ['style'] }),
31-
queryCollectionSearchSections('docsv4', { ignoredTags: ['style'] }),
32-
queryCollectionSearchSections('blog')
33-
])
34-
}, {
35-
server: false,
36-
transform: data => data.flat(),
37-
watch: [version]
38-
})
18+
useFetch('/api/navigation.json'),
19+
useFetch('/api/search.json', { server: false })
3920
])
4021
4122
onNuxtReady(() => {

modules/local.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default defineNuxtModule<ModuleOptions>({
2626

2727
if (options.uiOnly) {
2828
consola.info('Enabling UI-only mode for local development')
29-
nuxt.options.routeRules['/api/**'] = { proxy: { to: 'https://nuxt.com/api/**' } }
29+
nuxt.options.routeRules['/api/v1/**'] = { proxy: { to: 'https://nuxt.com/api/v1/**' } }
3030
}
3131
}
3232
})

nuxt.config.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ export default defineNuxtConfig({
4242
}
4343
},
4444
$production: {
45+
hub: {
46+
kv: {
47+
driver: 'vercel-runtime-cache'
48+
}
49+
},
4550
image: {
4651
ipx: {
4752
baseURL: 'https://ipx.nuxt.com'
@@ -116,6 +121,9 @@ export default defineNuxtConfig({
116121
// Admin
117122
'/admin': { ssr: false },
118123
'/admin/**': { ssr: false },
124+
// Main navigation
125+
'/api/navigation.json': { prerender: true },
126+
'/api/search.json': { prerender: true },
119127
// Redirects
120128
'/docs': { redirect: '/docs/getting-started/introduction', prerender: false },
121129
'/docs/3.x': { redirect: '/docs/3.x/getting-started/introduction', prerender: false },
@@ -279,9 +287,7 @@ export default defineNuxtConfig({
279287
},
280288
hub: {
281289
db: 'sqlite',
282-
kv: {
283-
driver: 'vercel-runtime-cache'
284-
},
290+
kv: true,
285291
cache: true
286292
},
287293
typescript: {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"@iconify-json/simple-icons": "^1.2.63",
3131
"@libsql/client": "^0.15.15",
3232
"@npm/types": "^2.1.0",
33-
"@nuxt/content": "https://pkg.pr.new/@nuxt/content@3624",
33+
"@nuxt/content": "^3.9.0",
3434
"@nuxt/hints": "1.0.0-alpha.3",
3535
"@nuxt/image": "^2.0.0",
3636
"@nuxt/scripts": "^0.13.1",

pnpm-lock.yaml

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

public/favicon.ico

4.19 KB
Binary file not shown.

server/api/contributors/index.get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export default cachedEventHandler(async () => {
33
}, {
44
name: 'contributors',
55
swr: true,
6-
maxAge: 60 * 5 // 5 minutes
6+
maxAge: 60 * 60 // 1 hour
77
})
88

99
interface NuxtersContributor {

server/api/jobs.get.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ export default cachedEventHandler(async () => {
1212
}, {
1313
name: 'nuxt-jobs',
1414
getKey: () => 'jobs',
15-
maxAge: 60 * 10 // 10 minutes
15+
maxAge: 60 * 60 * 24, // 1 day
16+
swr: true
1617
})

server/api/navigation.json.get.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This route will be pre-rendered as /api/navigation.json
2+
import { queryCollectionNavigation } from '@nuxt/content/server'
3+
4+
export default defineEventHandler(async (event) => {
5+
return Promise.all([
6+
queryCollectionNavigation(event, 'docsv3', ['titleTemplate']).then(data => data[0]?.children),
7+
queryCollectionNavigation(event, 'docsv4', ['titleTemplate']).then(data => data[0]?.children),
8+
queryCollectionNavigation(event, 'blog')
9+
]).then(data => data.flat())
10+
})

0 commit comments

Comments
 (0)