diff --git a/docs/latest/examples/websockets.md b/docs/latest/advanced/websockets.md similarity index 100% rename from docs/latest/examples/websockets.md rename to docs/latest/advanced/websockets.md diff --git a/docs/latest/examples/common-patterns.md b/docs/latest/examples/common-patterns.md index f14a3a9d..d9b44108 100644 --- a/docs/latest/examples/common-patterns.md +++ b/docs/latest/examples/common-patterns.md @@ -176,7 +176,7 @@ export const handler = define.handlers({ ## WebSockets Fresh provides first-class WebSocket support via `ctx.upgrade()`. See the full -[WebSocket guide](/docs/examples/websockets) for all options. +[WebSocket guide](/docs/advanced/websockets) for all options. ## Subdomain routing diff --git a/docs/latest/examples/index.md b/docs/latest/examples/index.md index f5a4b9f6..957bbe20 100644 --- a/docs/latest/examples/index.md +++ b/docs/latest/examples/index.md @@ -13,5 +13,4 @@ that you may like in your Fresh project. - [Sharing state between islands](./examples/sharing-state-between-islands) - [Active links](./examples/active-links) - [Session management](./examples/session-management) -- [WebSockets](./examples/websockets) - [Common Patterns](./examples/common-patterns) diff --git a/docs/toc.ts b/docs/toc.ts index 15c3937c..4d3c5d7c 100644 --- a/docs/toc.ts +++ b/docs/toc.ts @@ -61,6 +61,7 @@ const toc: RawTableOfContents = { ["environment-variables", "Environment Variables", "link:latest"], ["head", " element", "link:latest"], ["vite", "Vite Plugin Options", "link:latest"], + ["websockets", "WebSockets", "link:latest"], ["opentelemetry", "OpenTelemetry", "link:latest"], ["api-reference", "API Reference", "link:latest"], ["troubleshooting", "Troubleshooting", "link:latest"], @@ -107,7 +108,6 @@ const toc: RawTableOfContents = { ], ["active-links", "Active links", "link:latest"], ["session-management", "Session management", "link:latest"], - ["websockets", "WebSockets", "link:latest"], ["common-patterns", "Common Patterns", "link:latest"], ], }, diff --git a/www/components/CodeBlock.tsx b/www/components/CodeBlock.tsx index 9e6354da..7aff8a9f 100644 --- a/www/components/CodeBlock.tsx +++ b/www/components/CodeBlock.tsx @@ -5,7 +5,7 @@ export function CodeBlock( ) { return (
diff --git a/www/components/CodeWindow.tsx b/www/components/CodeWindow.tsx index 911255f0..94befe05 100644 --- a/www/components/CodeWindow.tsx +++ b/www/components/CodeWindow.tsx @@ -14,7 +14,7 @@ export function CodeWindow(props: CodeWindowProps) { style={props.style} >
-
+
-
+
{props.name ?? ""}
diff --git a/www/components/PageSection.tsx b/www/components/PageSection.tsx index ed525998..cf8baf07 100644 --- a/www/components/PageSection.tsx +++ b/www/components/PageSection.tsx @@ -4,7 +4,7 @@ export function PageSection(props: JSX.HTMLAttributes) { return (
diff --git a/www/components/SideBySide.tsx b/www/components/SideBySide.tsx index 1bd647a9..848dc1e1 100644 --- a/www/components/SideBySide.tsx +++ b/www/components/SideBySide.tsx @@ -26,7 +26,7 @@ export function SideBySide(props: SideBySideProps) { return (
*]:md:first:order-1" : "" } ${mdSplitClass} ${lgSplitClass} ${props.class ?? ""}`} > diff --git a/www/components/homepage/APIRoutesSection.tsx b/www/components/homepage/APIRoutesSection.tsx new file mode 100644 index 00000000..d03a7d69 --- /dev/null +++ b/www/components/homepage/APIRoutesSection.tsx @@ -0,0 +1,84 @@ +import { CodeBlock } from "../../components/CodeBlock.tsx"; +import { CodeWindow } from "../../components/CodeWindow.tsx"; +import { PageSection } from "../../components/PageSection.tsx"; +import { SideBySide } from "../../components/SideBySide.tsx"; +import { SectionHeading } from "../../components/homepage/SectionHeading.tsx"; +import { FancyLink } from "../../components/FancyLink.tsx"; + +const apiCode = `import { createDefine } from "fresh"; +const define = createDefine(); + +export const handlers = define.handlers({ + GET(ctx) { + const user = db.getUser(ctx.params.id); + return Response.json(user); + }, + POST(ctx) { + const body = await ctx.req.json(); + const user = db.updateUser(ctx.params.id, body); + return Response.json(user); + }, + DELETE(ctx) { + db.deleteUser(ctx.params.id); + return new Response(null, { status: 204 }); + }, +});`; + +export function APIRoutesSection() { + return ( + + +
+ + Handlers for every method +

+ Define{" "} + + GET + ,{" "} + + POST + ,{" "} + + DELETE + {" "} + — any HTTP method as a named handler on your route. Fresh maps + requests to the right function automatically, with full type safety. +

+ + Learn about handlers + +
+
+ + + +
+
+
+ ); +} diff --git a/www/components/homepage/DemoBox.tsx b/www/components/homepage/DemoBox.tsx index e9157d56..e300b5bd 100644 --- a/www/components/homepage/DemoBox.tsx +++ b/www/components/homepage/DemoBox.tsx @@ -9,7 +9,7 @@ export function DemoBox(props: DemoBoxProps) { const innerFlip = props.flip ? "skew-y-2 skew-x-3" : "-skew-y-2 -skew-x-3"; return (
{props.children} diff --git a/www/components/homepage/ExampleArrow.tsx b/www/components/homepage/ExampleArrow.tsx index 4d99dc61..2f7d243e 100644 --- a/www/components/homepage/ExampleArrow.tsx +++ b/www/components/homepage/ExampleArrow.tsx @@ -13,7 +13,7 @@ export function ExampleArrow( xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;" - class={`w-12 -my-8 relative z-10 mx-auto ${props?.class ?? ""}`} + class={`w-8 -my-6 relative z-10 mx-auto ${props?.class ?? ""}`} >
- - Forms, the right way - + Forms that just work

- Don't fight the browser. Fresh helps you handle form submissions and - other dynamic requests server-side, from any route. -

-

- Since Fresh is built on{" "} - Deno, it's built on - web standards. + Handle submissions server-side with standard Request and FormData. + No client-side state management, no serialization headaches. + Progressive enhancement comes free.

Forms in Fresh diff --git a/www/components/homepage/HeadSection.tsx b/www/components/homepage/HeadSection.tsx new file mode 100644 index 00000000..64d29121 --- /dev/null +++ b/www/components/homepage/HeadSection.tsx @@ -0,0 +1,86 @@ +import { CodeBlock } from "../../components/CodeBlock.tsx"; +import { CodeWindow } from "../../components/CodeWindow.tsx"; +import { PageSection } from "../../components/PageSection.tsx"; +import { SideBySide } from "../../components/SideBySide.tsx"; +import { SectionHeading } from "../../components/homepage/SectionHeading.tsx"; +import { FancyLink } from "../../components/FancyLink.tsx"; + +const headCode = `import { Head } from "fresh/runtime"; + +export default function MyPage() { + return ( + <> + + My Page + + + +

Hello, world!

+ + ); +}`; + +export function HeadSection() { + return ( + + +
+ + + Full control of{" "} + + +

+ Use the{" "} + {" "} + component from any page or island to set titles, meta tags, + stylesheets, and scripts — no hoisting hacks or side channels + needed. +

+ + + +
+
+ + + +
+
+
+ ); +} diff --git a/www/components/homepage/Hero.tsx b/www/components/homepage/Hero.tsx index 73e8999f..14ee4b83 100644 --- a/www/components/homepage/Hero.tsx +++ b/www/components/homepage/Hero.tsx @@ -9,15 +9,20 @@ export function Hero() {
+

Introducing Fresh:

- The simple, approachable, productive web framework + The framework so simple, you already know it.

+

+ No config files, no build step, no node_modules. Just one file and + you have a server with routing, JSX, and islands. +

Get started
-
+
diff --git a/www/components/homepage/IslandsSection.tsx b/www/components/homepage/IslandsSection.tsx index 61aca250..f8a5cf97 100644 --- a/www/components/homepage/IslandsSection.tsx +++ b/www/components/homepage/IslandsSection.tsx @@ -40,8 +40,8 @@ export function IslandsSection() { aria-hidden="true" xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-beach text-fresh" - width="4rem" - height="4rem" + width="2.5rem" + height="2.5rem" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" @@ -56,17 +56,19 @@ export function IslandsSection() { - Island-based architecture + Interactive where it matters

- Fresh ships plain HTML to the client, then hydrates with JavaScript - only where needed. + Most of your page is static HTML. Islands are the small, interactive + parts that get hydrated with JavaScript. You choose exactly what + runs on the client.

- Because it's Preact, you get best-in-class performance, plus the - convenience of{" "} + Built on{" "} + Preact and + {" "} Signals - . + , so islands are tiny and reactive out of the box.

Learn more about islands diff --git a/www/components/homepage/MoreFeatures.tsx b/www/components/homepage/MoreFeatures.tsx new file mode 100644 index 00000000..bcbfcb20 --- /dev/null +++ b/www/components/homepage/MoreFeatures.tsx @@ -0,0 +1,416 @@ +import { CodeBlock } from "../../components/CodeBlock.tsx"; +import { PageSection } from "../../components/PageSection.tsx"; +import { SectionHeading } from "../../components/homepage/SectionHeading.tsx"; + +const features = [ + { + title: "View Transitions", + description: + "Native-feeling page transitions with a single config flag. Customize per-element with plain CSS.", + href: "/docs/advanced/view-transitions", + icon: ( + + ), + code: `const app = new App({ + viewTransition: true, +});`, + lang: "js" as const, + }, + { + title: "Route Handlers", + description: + "Define GET, POST, DELETE, or any HTTP method as a named handler on your route, with full type safety.", + href: "/docs/concepts/routing", + icon: ( + + ), + code: `export const handlers = define.handlers({ + GET(ctx) { /* ... */ }, + POST(ctx) { /* ... */ }, + DELETE(ctx) { /* ... */ }, +});`, + lang: "js" as const, + }, + { + title: "WebSockets", + description: + "Add real-time endpoints with app.ws(). Define open, message, and close handlers in a single object.", + href: "/docs/advanced/websockets", + icon: ( + + ), + code: `app.ws("/chat", { + open(socket) { /* ... */ }, + message(socket, event) { + socket.send(event.data); + }, +});`, + lang: "js" as const, + }, + { + title: " Component", + description: + "Set titles, meta tags, stylesheets, and scripts from any page or island. No hoisting hacks needed.", + href: "/docs/advanced/head", + icon: ( + + ), + code: ` + My Page + +`, + lang: "jsx" as const, + }, + { + title: "OpenTelemetry", + description: + "Auto-injects a traceparent meta tag into every page, connecting browser traces to server spans.", + href: "/docs/advanced/opentelemetry", + icon: ( + + ), + code: `const app = new App({ + otel: true, +});`, + lang: "js" as const, + }, + { + title: "Content Security Policy", + description: + "Automatic nonce injection for inline scripts and styles. Strong security defaults with zero boilerplate.", + href: "/docs/plugins/csp", + icon: ( + + ), + code: `app.use(csp({ + directives: { + scriptSrc: ["'nonce'"], + }, +}));`, + lang: "js" as const, + }, +]; + +const extras = [ + { + title: "File-based routing", + description: + "Drop a file in routes/, get a URL. Dynamic params via [id].tsx.", + href: "/docs/concepts/file-routing", + icon: ( + + ), + }, + { + title: "Middleware", + description: "Chain auth, logging, or any logic before your routes run.", + href: "/docs/concepts/middleware", + icon: ( + + ), + }, + { + title: "Zero-config TypeScript", + description: "Just write .tsx. No tsconfig, no build step, it just works.", + href: "/docs/concepts/routing", + icon: ( + + ), + }, + { + title: "Deploy anywhere", + description: + "Deno Deploy, Docker, Cloudflare Workers, or a single binary with deno compile.", + href: "/docs/deployment/deno-deploy", + icon: ( + + ), + }, + { + title: "Layouts", + description: + "Nested layouts that compose automatically from the file system.", + href: "/docs/concepts/layouts", + icon: ( + + ), + }, + { + title: "Built-in plugins", + description: + "CORS, CSRF, IP filtering, and trailing slashes out of the box.", + href: "/docs/plugins/cors", + icon: ( + + ), + }, +]; + +export function MoreFeatures() { + return ( +
+ +
+ And so much more +
+ +
+

(…and even more)

+
+
+ {extras.map((e) => ( + +
+

{e.title}

+ {e.icon} +
+

{e.description}

+
+ ))} +
+
+
+ ); +} diff --git a/www/components/homepage/PartialsSection.tsx b/www/components/homepage/PartialsSection.tsx index 0bbd977e..b4f04d8a 100644 --- a/www/components/homepage/PartialsSection.tsx +++ b/www/components/homepage/PartialsSection.tsx @@ -45,8 +45,8 @@ export function PartialsSection() { aria-hidden="true" xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-arrows-transfer-down text-fresh" - width="4rem" - height="4rem" + width="2.5rem" + height="2.5rem" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" @@ -66,9 +66,10 @@ export function PartialsSection() { Stream HTML straight from the server

- Fresh Partials let you fetch HTML and slot it directly into the - page, without a full page reload - perfect for interactive elements - and dynamic apps. + Swap chunks of HTML from the server straight into the page. No full + reload, no client-side routing library. Click a link or submit a + form and Fresh streams just the part that changed. Perfect for + interactive elements and dynamic apps.

Learn more about Partials diff --git a/www/components/homepage/RecipeDemo.tsx b/www/components/homepage/RecipeDemo.tsx index 9e96433c..0ad6583a 100644 --- a/www/components/homepage/RecipeDemo.tsx +++ b/www/components/homepage/RecipeDemo.tsx @@ -3,16 +3,28 @@ import { Partial } from "fresh/runtime"; export const RecipeDemo = () => (
diff --git a/www/components/homepage/RenderingSection.tsx b/www/components/homepage/RenderingSection.tsx index 4c836cad..77c6a4bc 100644 --- a/www/components/homepage/RenderingSection.tsx +++ b/www/components/homepage/RenderingSection.tsx @@ -7,9 +7,10 @@ import { DemoBox } from "../../components/homepage/DemoBox.tsx"; import { ExampleArrow } from "../../components/homepage/ExampleArrow.tsx"; const serverCode = `export default function HomePage() { - const time = new Date().toLocaleString(); + const now = Temporal.Now.plainDateTimeISO() + .toLocaleString("en-US"); return ( -

Freshly server-rendered {time}

+

Freshly server-rendered {now}

); }`; @@ -22,8 +23,8 @@ export function RenderingSection() { aria-hidden="true" xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-atom text-fresh" - width="4rem" - height="4rem" + width="2.5rem" + height="2.5rem" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" @@ -38,16 +39,13 @@ export function RenderingSection() { - - Build fast apps fast - + Server-rendered by default

- Fresh routes are dynamically server-rendered{" "} + Every route renders on the server as a{" "} Preact{" "} - components, so there's zero JavaScript shipped to the browser by - default. + component. Zero JavaScript hits the browser unless you opt in with + an island. Pages are fast because they start as plain HTML.

-

Simple to write; fast to run.

@@ -56,10 +54,8 @@ export function RenderingSection() { {" "}

- Freshly server-rendered {new Date().toLocaleString("default", { - dateStyle: "medium", - timeStyle: "medium", - })} UTC + Freshly server-rendered{" "} + {Temporal.Now.plainDateTimeISO().toLocaleString("en-US")}

diff --git a/www/components/homepage/SectionHeading.tsx b/www/components/homepage/SectionHeading.tsx index 166c0f97..e116e6f0 100644 --- a/www/components/homepage/SectionHeading.tsx +++ b/www/components/homepage/SectionHeading.tsx @@ -4,7 +4,7 @@ export function SectionHeading( { children }: { children: ComponentChildren }, ) { return ( -

+

{children}

); diff --git a/www/components/homepage/SecuritySection.tsx b/www/components/homepage/SecuritySection.tsx new file mode 100644 index 00000000..ad9ddcfd --- /dev/null +++ b/www/components/homepage/SecuritySection.tsx @@ -0,0 +1,69 @@ +import { CodeBlock } from "../../components/CodeBlock.tsx"; +import { CodeWindow } from "../../components/CodeWindow.tsx"; +import { PageSection } from "../../components/PageSection.tsx"; +import { SideBySide } from "../../components/SideBySide.tsx"; +import { SectionHeading } from "../../components/homepage/SectionHeading.tsx"; +import { FancyLink } from "../../components/FancyLink.tsx"; + +const otelCode = `import { App } from "fresh"; + +// When OpenTelemetry is active, Fresh +// auto-injects a +// tag — connecting browser traces to +// server spans, zero config required +const app = new App(); + +app.listen();`; + +export function SecuritySection() { + return ( + + +
+ + OpenTelemetry, built in +

+ When OpenTelemetry is active, Fresh automatically injects a{" "} + + traceparent + {" "} + meta tag into every page — connecting your browser traces to server + spans end-to-end, zero config required. +

+

+ Get full-stack observability across your entire request lifecycle + with zero configuration. +

+ + Learn about OpenTelemetry + +
+
+ + + +
+
+
+ ); +} diff --git a/www/components/homepage/Simple.tsx b/www/components/homepage/Simple.tsx index b161d102..508ccfef 100644 --- a/www/components/homepage/Simple.tsx +++ b/www/components/homepage/Simple.tsx @@ -1,31 +1,40 @@ import { PageSection } from "../../components/PageSection.tsx"; +import { CodeBlock } from "../../components/CodeBlock.tsx"; +import { CodeWindow } from "../../components/CodeWindow.tsx"; -const ONE_FILE_EXAMPLE = `import { App } from "fresh"; +const TRADITIONAL = `// package.json +// tsconfig.json +// next.config.js +// postcss.config.js +// tailwind.config.js +// .eslintrc.json +// app/layout.tsx +// app/page.tsx -const app = new App() - .get("/", () => new Response("Hello, World!")); +// app/api/hello/route.ts +import { NextResponse } from "next/server"; -app.listen();`; - -const ADD_JSX_EXAMPLE = `import { App } from "fresh"; - -const app = new App() - .get("/", (ctx) => ctx.render(

Hello!

)); - -app.listen();`; - -const ADD_ISLAND_EXAMPLE = `// islands/Counter.tsx -import { useSignal } from "@preact/signals"; - -export function Counter() { - const count = useSignal(0); - return ( - - ); +export async function GET() { + return NextResponse.json({ + message: "Hello!", + }); }`; +const FRESH_EXAMPLE = `// main.ts — that's it. +import { App } from "fresh"; + +const app = new App() + .get("/", (ctx) => + ctx.render(

Hello!

) + ) + .get("/api/hello", () => + Response.json({ + message: "Hello!", + }) + ); + +app.listen();`; + export function Simple() { return ( @@ -35,50 +44,29 @@ export function Simple() { The framework so simple, you already know it.

- Fresh is designed to be easy to use by building on the best well-known - tools, conventions, and web standards. + No config files, no build step, no node_modules. Just one file and you + have a server with routing, JSX, and islands.

-
- - - +
+
+

+ The traditional way +

+ + + +
+
+

+ The Fresh way +

+ + + +
); } - -function StepCard( - props: { step: string; title: string; description: string; code: string }, -) { - return ( -
-
- - {props.step} - -

{props.title}

-
-

{props.description}

-
-        {props.code}
-      
-
- ); -} diff --git a/www/components/homepage/SocialProof.tsx b/www/components/homepage/SocialProof.tsx index 4b7229ad..c3fec4a3 100644 --- a/www/components/homepage/SocialProof.tsx +++ b/www/components/homepage/SocialProof.tsx @@ -19,8 +19,8 @@ export function SocialProof() { Deco CX diff --git a/www/components/homepage/TransitionsSection.tsx b/www/components/homepage/TransitionsSection.tsx new file mode 100644 index 00000000..dbb85e46 --- /dev/null +++ b/www/components/homepage/TransitionsSection.tsx @@ -0,0 +1,81 @@ +import { CodeBlock } from "../../components/CodeBlock.tsx"; +import { CodeWindow } from "../../components/CodeWindow.tsx"; +import { PageSection } from "../../components/PageSection.tsx"; +import { SideBySide } from "../../components/SideBySide.tsx"; +import { SectionHeading } from "../../components/homepage/SectionHeading.tsx"; +import { FancyLink } from "../../components/FancyLink.tsx"; + +const transitionCode = `import { App } from "fresh"; + +const app = new App({ + // Enable the View Transitions API + // for smooth client-side navigation + viewTransition: true, +}); + +app.listen();`; + +const cssCode = `/* Style your transitions with CSS */ +::view-transition-old(root) { + animation: fade-out 0.2s ease-in; +} +::view-transition-new(root) { + animation: fade-in 0.2s ease-out; +}`; + +export function TransitionsSection() { + return ( + + +
+ + Smooth View Transitions +

+ Fresh supports the{" "} + + View Transitions API + {" "} + out of the box, giving your app native-feeling page transitions with + a single config flag. +

+

+ Pages crossfade automatically. Customize animations per-element with + plain CSS — no JavaScript animation libraries needed. +

+ + Learn about View Transitions + +
+
+ + + + + + +
+
+
+ ); +} diff --git a/www/components/homepage/WebSocketSection.tsx b/www/components/homepage/WebSocketSection.tsx new file mode 100644 index 00000000..a3ed9485 --- /dev/null +++ b/www/components/homepage/WebSocketSection.tsx @@ -0,0 +1,72 @@ +import { CodeBlock } from "../../components/CodeBlock.tsx"; +import { CodeWindow } from "../../components/CodeWindow.tsx"; +import { PageSection } from "../../components/PageSection.tsx"; +import { SideBySide } from "../../components/SideBySide.tsx"; +import { SectionHeading } from "../../components/homepage/SectionHeading.tsx"; +import { FancyLink } from "../../components/FancyLink.tsx"; + +const wsCode = `import { App } from "fresh"; + +const app = new App(); + +app.ws("/chat", { + open(socket) { + console.log("Client connected"); + }, + message(socket, event) { + // Echo the message back + socket.send(\`You said: \${event.data}\`); + }, + close(socket) { + console.log("Client disconnected"); + }, +}); + +app.listen();`; + +export function WebSocketSection() { + return ( + + +
+ + First-class WebSockets +

+ Add real-time endpoints with{" "} + + app.ws() + {" "} + — define open, message, and close handlers in a single object. Build + chat, live dashboards, or collaborative editing without leaving + Fresh. +

+ + Learn about WebSockets + +
+
+ + + +
+
+
+ ); +} diff --git a/www/islands/FormSubmitDemo.tsx b/www/islands/FormSubmitDemo.tsx index 249b9bd2..49a857fa 100644 --- a/www/islands/FormSubmitDemo.tsx +++ b/www/islands/FormSubmitDemo.tsx @@ -4,7 +4,10 @@ export function FormSubmitDemo() {
What's your favorite treat? -
- +

+ Take a tour of Fresh +

+ @@ -73,11 +76,15 @@ export default define.page(function MainPage() { function HelloBar() { return ( - Fresh 2 released with Vite{" "} - → + Fresh 2.3 is here! + + + WebSockets, View Transitions, Temporal API, and more{" "} + → + ); } diff --git a/www/static/showcase/deco.webp b/www/static/showcase/deco.webp new file mode 100644 index 00000000..583755ed Binary files /dev/null and b/www/static/showcase/deco.webp differ