Skip to content

The Open Source DocuSign Alternative.

feat: add static cache

David Nguyen8d5fafec27ef
diff --git a/apps/remix/app/root.tsx b/apps/remix/app/root.tsx
index 13b7bd7fe..5238612b5 100644
--- a/apps/remix/app/root.tsx
+++ b/apps/remix/app/root.tsx
@@ -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 (
diff --git a/apps/remix/server/main.js b/apps/remix/server/main.js
index f9ec71993..03cf53767 100644
--- a/apps/remix/server/main.js
+++ b/apps/remix/server/main.js
@@ -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');
+ }
+ },
}),
);