feat: add static cache
This commit is contained in:
@@ -17,7 +17,7 @@ import { getOptionalLoaderSession } from 'server/utils/get-loader-session';
|
|||||||
|
|
||||||
import { SessionProvider } from '@documenso/lib/client-only/providers/session';
|
import { SessionProvider } from '@documenso/lib/client-only/providers/session';
|
||||||
import { APP_I18N_OPTIONS, type SupportedLanguageCodes } from '@documenso/lib/constants/i18n';
|
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 { extractLocaleData } from '@documenso/lib/utils/i18n';
|
||||||
import { TrpcProvider } from '@documenso/trpc/react';
|
import { TrpcProvider } from '@documenso/trpc/react';
|
||||||
import { Toaster } from '@documenso/ui/primitives/toaster';
|
import { Toaster } from '@documenso/ui/primitives/toaster';
|
||||||
@@ -34,6 +34,7 @@ import { appMetaTags } from './utils/meta';
|
|||||||
|
|
||||||
const { trackPageview } = Plausible({
|
const { trackPageview } = Plausible({
|
||||||
domain: 'documenso.com',
|
domain: 'documenso.com',
|
||||||
|
trackLocalhost: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const links: Route.LinksFunction = () => [
|
export const links: Route.LinksFunction = () => [
|
||||||
@@ -147,7 +148,9 @@ export default function AppWithTheme({ loaderData }: Route.ComponentProps) {
|
|||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (env('NODE_ENV') === 'production') {
|
||||||
trackPageview();
|
trackPageview();
|
||||||
|
}
|
||||||
}, [location.pathname]);
|
}, [location.pathname]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -16,6 +16,15 @@ import * as build from './index.js';
|
|||||||
server.use(
|
server.use(
|
||||||
serveStatic({
|
serveStatic({
|
||||||
root: 'build/client',
|
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');
|
||||||
|
}
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user