feat: add static cache

This commit is contained in:
David Nguyen
2025-02-15 00:08:36 +11:00
parent 0f6f236e0c
commit 8d5fafec27
2 changed files with 14 additions and 2 deletions

View File

@ -17,7 +17,7 @@ import { getOptionalLoaderSession } from 'server/utils/get-loader-session';
import { SessionProvider } from '@documenso/lib/client-only/providers/session';
import { APP_I18N_OPTIONS, type SupportedLanguageCodes } from '@documenso/lib/constants/i18n';
import { createPublicEnv } from '@documenso/lib/utils/env';
import { createPublicEnv, env } from '@documenso/lib/utils/env';
import { extractLocaleData } from '@documenso/lib/utils/i18n';
import { TrpcProvider } from '@documenso/trpc/react';
import { Toaster } from '@documenso/ui/primitives/toaster';
@ -34,6 +34,7 @@ import { appMetaTags } from './utils/meta';
const { trackPageview } = Plausible({
domain: 'documenso.com',
trackLocalhost: false,
});
export const links: Route.LinksFunction = () => [
@ -147,7 +148,9 @@ export default function AppWithTheme({ loaderData }: Route.ComponentProps) {
const location = useLocation();
useEffect(() => {
trackPageview();
if (env('NODE_ENV') === 'production') {
trackPageview();
}
}, [location.pathname]);
return (

View File

@ -16,6 +16,15 @@ import * as build from './index.js';
server.use(
serveStatic({
root: 'build/client',
onFound: (path, c) => {
if (path.startsWith('./build/client/assets')) {
// Hard cache assets with hashed file names.
c.header('Cache-Control', `public, immutable, max-age=31536000`);
} else {
// Cache with revalidation for rest of static files.
c.header('Cache-Control', 'no-cache, stale-while-revalidate');
}
},
}),
);