Skip to content

Commit

Permalink
feat: cache assets
Browse files Browse the repository at this point in the history
  • Loading branch information
holtwick committed Jan 10, 2025
1 parent 96a5ef2 commit 71de70c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions zerva-vite/src/module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { InlineConfig } from 'vite'
import type { LogConfig } from 'zeed'
import { existsSync } from 'node:fs'

import { resolve } from 'node:path'
import process from 'node:process'
import { on, register } from '@zerva/core'
import { LoggerFromConfig, LogLevelInfo, toHumanReadableFilePath, toPath } from 'zeed'
import type { InlineConfig } from 'vite'
import type { LogConfig } from 'zeed'
import { zervaMultiPageAppIndexRouting } from './multi'
import '@zerva/http'

Expand Down Expand Up @@ -95,6 +94,12 @@ export function useVite(config?: {

const multiInputCache: Record<string, string> = {}

// Cache static assets
app.get(/[^\/]assets\//, (req: any, res: any) => {
res.setHeader('Cache-Control', 'max-age=31536000, immutable')
// Cache-Control: max-age=31536000, immutable
})

// Map dynamic routes to index.html
app?.get(/.*/, (req: any, res: any) => {
let path: string | undefined = multiInputCache[req.path]
Expand Down

0 comments on commit 71de70c

Please sign in to comment.