Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
Cache css (#612)
Ivan Starkovbe0454fcbce0
diff --git a/apps/designer/app/routes/$.tsx b/apps/designer/app/routes/$.tsxindex 4baf19e6f5..a9f2202a95 100644--- a/apps/designer/app/routes/$.tsx+++ b/apps/designer/app/routes/$.tsx@@ -5,6 +5,7 @@ import type {ErrorBoundaryComponent,} from "@remix-run/node";import { useLoaderData } from "@remix-run/react";+import djb2a from "djb2a";import { InstanceRoot, Root } from "@webstudio-is/react-sdk";import { loadCanvasData } from "~/shared/db";import env, { type Env } from "~/env.server";@@ -29,6 +30,11 @@ export const dynamicLinks: DynamicLinksFunction<CanvasData> = ({}) => {const searchParams = new URLSearchParams(location.search);searchParams.set("pageId", data.page.id);++ // Break cache in case of css has changed+ const cssHash = djb2a(JSON.stringify(data.tree));+ searchParams.set("css-hash", `${cssHash}`);+return [{rel: "stylesheet",diff --git a/apps/designer/app/routes/s/css.ts b/apps/designer/app/routes/s/css.tsindex 7d3a5e7f30..6b6a42bf44 100644--- a/apps/designer/app/routes/s/css.ts+++ b/apps/designer/app/routes/s/css.ts@@ -18,6 +18,8 @@ export const loader: ActionFunction = async ({ request }) => {return new Response(cssText, {headers: {"Content-Type": "text/css",+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control+ "Cache-Control": "public, max-age=31536000, immutable",},});} catch (error) {diff --git a/apps/designer/package.json b/apps/designer/package.jsonindex 5a6fe48447..1ca1c41311 100644--- a/apps/designer/package.json+++ b/apps/designer/package.json@@ -39,6 +39,7 @@"css-tree": "^2.3.0","debug": "^4.3.4","detect-font": "^0.1.5",+ "djb2a": "^2.0.0","downshift": "^6.1.7","hyphenate-style-name": "^1.0.4","immer": "^9.0.12",diff --git a/apps/designer/remix.config.js b/apps/designer/remix.config.jsindex e5118bd6db..7ea30786e2 100644--- a/apps/designer/remix.config.js+++ b/apps/designer/remix.config.js@@ -12,7 +12,7 @@ module.exports = {// This makes sure remix bundles monorepo packages which are always// sym-linked and can't be hoisted. You could also manually name packages// e.g. ["@webstudio-is/ui", ...]- serverDependenciesToBundle: [/@webstudio-is\/.*/, "pretty-bytes"],+ serverDependenciesToBundle: [/@webstudio-is\/.*/, "pretty-bytes", "djb2a"],// appDirectory: "app",// assetsBuildDirectory: "public/build",serverBuildPath: "api/index.js",diff --git a/yarn.lock b/yarn.lockindex 03edc83ea5..e12f75c461 100644--- a/yarn.lock+++ b/yarn.lock@@ -8594,6 +8594,11 @@ dir-glob@^3.0.1:dependencies:path-type "^4.0.0"+djb2a@^2.0.0:+ version "2.0.0"+ resolved "https://registry.yarnpkg.com/djb2a/-/djb2a-2.0.0.tgz#63ad541b06b821de4b81ea7d59420cad76ce41aa"+ integrity sha512-mSkCTNSJRGjNUADzWx1ubTGxJh2IVY9uoc/WGozUIu0mgBUEvIyBn9uTs9jqFBbJxQthJMF3uDx0cnpdlAUo4Q==+doctrine@^2.1.0:version "2.1.0"resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-2.1.0.tgz#5cd01fc101621b42c4cd7f5d1a66243716d3f39d"