SlideShare a Scribd company logo
Fresh: a full stack web
framework for Deno
Nick Taylor
About Me
● Senior Software Engineer at OpenSauced
● From Montreal, Quebec, Canada
● I’m @nickytonline everywhere
● On the web at nickyt.co
● Streaming at nickyt.live
● Not a big fan of spiders
What We’ll Cover
What We’ll Cover
● What is Deno?
● Web Standards
● What is Fresh?
● Features
● Demo
● Questions
What is Deno?
What is Deno?
● Runtime for JavaScript, TypeScript & Web Assembly that uses V8
● Built-in code formatter
● Built-in test runner
● Node.js interoperability via node specifiers
● npm interoperability via npm specifiers and CDNs
What is Deno?
For the Web, Deno runs pretty much anywhere
● Deno Deploy, edge-optimized and recommended by Deno
● Deno Deploy Subhosting, e.g. Netlify Edge Functions, Supabase
Edge Functions
● Cloud platforms like fly.io and Railway
● serverless/container services
● self-hosted servers
What is Deno?
● Deno was originally written in Go
● Go has a garbage collector and so does V8
● Two garbage collectors === use Rust instead
● Nice side effect of Rust: WASM unlock
🦀
What is Deno?
Web Standards
Deno uses web standards
● import maps
● Fetch
● Request and Response
● etc.
Web Standards
Deno is a part of the Web-interoperable Runtimes Community Group
(WinterCG).
The group provides a space for JavaScript runtimes to collaborate on
API interoperability
Web Standards
What is Fresh?
Fresh is a full-stack web framework that runs on Deno.
● Server-side rendered (SSR) framework
● Just-in-time (JIT) rendering on the edge
● Provides TypeScript support out of the box
● Nothing to configure to get up and running
What is Fresh?
● No JavaScript delivered by default
● Islands Architecture for client interactivity
● Preact (server-side and client-side)
● JSX support (thanks Preact and TypeScript!)
deno run -A -r https://fresh.deno.dev
Nick Taylor - A Full Stack Web Framework for Deno
What is Fresh?
What is Fresh?
Features
Features
● Static files
● Routes & Routing
● Data Fetching
● Middleware
● Error pages
Features
● Styling
● Islands
● Signals
● Partials
Static Files
Static Files
● All static assets reside in the `/static` folder
● No caching headers by default for static assets
○ Exceptions: src and srcset attributes on <img /> and <source/>
elements
● Use the asset helper to automatically cache for a year
Static Files
/styles.css?
__frsh_c=5rs329q7fe2g
Routes & Routing
Routes & Routing
● 3 kinds of routes:
○ Handler route (API route)
○ Component route (Pages)
○ Hybrid route (handler and component)
■ form that POSTs back,
■ search page that GETs search results
Routes & Routing
● Routes can be dynamic
https://fresh.deno.dev/docs/concepts/routing
Data Fetching
Data Fetching
Handler routes and Hybrid routes handle data fetching
Data Fetching
● For handler routes (APIs), export function that returns a response
Data Fetching
● For hybrid routes, define functions for actions in an exported
variable called handler
● Name async functions after HTTP verbs: GET, POST etc.
Data Fetching
Middleware
● Has to be named _middleware.ts.
● Resides in the /routes folder
● Multiple middlewares are supported
Middleware
Middleware
Root middleware runs
1st
Movie subfolder middleware runs
2nd
Middleware
Middleware 1 Middleware 2
http://localhost:8000/movies/1
Error Pages
Error Pages
● Create custom error pages: 404, 500 etc.
● Must be in the root of the /routes folder
Error Pages
Error Pages
● For a dynamic route, call ctx.renderNotFound() to render the 404
page if page does not exist
Error Pages
Styling
Styling
● Twind, a server-side rendered implementation of Tailwind
● Tailwind
● Modern CSS on its own is pretty awesome
● Expect innovation here from userland
Islands
Islands
Pockets of interactivity
Islands
“The general idea of an “Islands” architecture is deceptively simple:
render HTML pages on the server, and inject placeholders or slots
around highly dynamic regions. These placeholders/slots contain
the server-rendered HTML output from their corresponding widget.
They denote regions that can then be "hydrated" on the client into
small self-contained widgets, reusing their server-rendered initial
HTML.”
https://jasonformat.com/islands-architecture – Jason Miller
Islands
● Must reside in /islands folder
Islands
How do we revive an island?
How do we revive an island?
● A script of type application/json holds the initial state of any islands
How do we revive an island?
How do we revive an island?
How do we revive an island?
● Since Fresh uses Preact, signals are available on the client-side.
● Alternative to useState, useReducer…
Signals
“At its core, a signal is an object with a .value property that holds a
value. This has an important characteristic: a signal's value can
change, but the signal itself always stays the same”
– Preact Signals documentation
Signals
Signals
Signals
Signals
● Enables client-side routing to give a snappier feel to your app
● Requires an HTML attribute f-client-nav on a container element,
e.g. <body />
● Wrap main content with a <Partial /> component
Partials
Partials
● Can do more granular partials if you want to
● See the documentation on Partials
Partials
Demo time
demo deployed at
nickyt.co/ato-fresh
demo source code
github.com/nickytonline/ato-fresh
Nick Taylor - A Full Stack Web Framework for Deno
Resources
Resources
● Fresh Website
● Fresh: a new full stack web framework for Deno with Luca Casonat
o
● Fresh 1.5: Partials, client side navigation and more
● Fresh 1.6: Tailwind CSS plugin, simplified typings and more
● Islands Architecture
● A Gentle Introduction to Islands
● Installing Deno
● Preact
● Preact Signals
Resources
● Installing Deno
● Preact
● Preact Signals
● WTF is JSX?
● What is Deno?
● TypeScript Language
● Import maps
● Fetch API
● revive() function
● WinterCG
Resources
● Request
● Response
● Twind
● Deno: node: specifiers
● Deno: npm via CDNs
● Deno: npm: specifiers
● import maps
slide deck available at
nickyt.co/slides/ato24
Stay in touch!
● @nickytonline everywhere
● nickyt.co
● nickyt.live
● github.com/nickytonline
That’s All Folks!

More Related Content

Similar to Nick Taylor - A Full Stack Web Framework for Deno (20)

PDF
Servlet., tomcat server, implicit jsp object
ADITYADIXIT974283
 
PPTX
Angular or React
Orkhan Gasimov
 
PPTX
Dart the Better JavaScript
Jorg Janke
 
ODP
Deploying Perl apps on dotCloud
daoswald
 
PDF
Front-End Developer's Career Roadmap
WebStackAcademy
 
PDF
Netflix Open Source Meetup Season 4 Episode 2
aspyker
 
PPTX
JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]
Leonardo Zanivan
 
PDF
Angular (v2 and up) - Morning to understand - Linagora
LINAGORA
 
PPTX
Foster - Getting started with Angular
MukundSonaiya1
 
PDF
JSFest 2019: Technology agnostic microservices at SPA frontend
Vlad Fedosov
 
PPTX
Progressive web applications
Tom Martin
 
PDF
GWT - Building Rich Internet Applications Using OO Tools
barciszewski
 
PDF
Varnish - PLNOG 4
Leszek Urbanski
 
PDF
New power of Angular2 Router
Zhentian Wan
 
PPTX
Android Lollipop: The developer's perspective
Sebastian Vieira
 
PDF
CON6423: Scalable JavaScript applications with Project Nashorn
Michel Graciano
 
PDF
Go at uber
Rob Skillington
 
PDF
Creating a custom API for a headless Drupal
Exove
 
PPTX
Truemotion Adventures in Containerization
Ryan Hunter
 
PDF
Treinamento frontend
Adrian Caetano
 
Servlet., tomcat server, implicit jsp object
ADITYADIXIT974283
 
Angular or React
Orkhan Gasimov
 
Dart the Better JavaScript
Jorg Janke
 
Deploying Perl apps on dotCloud
daoswald
 
Front-End Developer's Career Roadmap
WebStackAcademy
 
Netflix Open Source Meetup Season 4 Episode 2
aspyker
 
JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]
Leonardo Zanivan
 
Angular (v2 and up) - Morning to understand - Linagora
LINAGORA
 
Foster - Getting started with Angular
MukundSonaiya1
 
JSFest 2019: Technology agnostic microservices at SPA frontend
Vlad Fedosov
 
Progressive web applications
Tom Martin
 
GWT - Building Rich Internet Applications Using OO Tools
barciszewski
 
Varnish - PLNOG 4
Leszek Urbanski
 
New power of Angular2 Router
Zhentian Wan
 
Android Lollipop: The developer's perspective
Sebastian Vieira
 
CON6423: Scalable JavaScript applications with Project Nashorn
Michel Graciano
 
Go at uber
Rob Skillington
 
Creating a custom API for a headless Drupal
Exove
 
Truemotion Adventures in Containerization
Ryan Hunter
 
Treinamento frontend
Adrian Caetano
 

More from All Things Open (20)

PDF
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
All Things Open
 
PPTX
Big Data on a Small Budget: Scalable Data Visualization for the Rest of Us - ...
All Things Open
 
PDF
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
 
PDF
Let's Create a GitHub Copilot Extension! - Nick Taylor, Pomerium
All Things Open
 
PDF
Leveraging Pre-Trained Transformer Models for Protein Function Prediction - T...
All Things Open
 
PDF
Gen AI: AI Agents - Making LLMs work together in an organized way - Brent Las...
All Things Open
 
PDF
You Don't Need an AI Strategy, But You Do Need to Be Strategic About AI - Jes...
All Things Open
 
PPTX
DON’T PANIC: AI IS COMING – The Hitchhiker’s Guide to AI - Mark Hinkle, Perip...
All Things Open
 
PDF
Fine-Tuning Large Language Models with Declarative ML Orchestration - Shivay ...
All Things Open
 
PDF
Leveraging Knowledge Graphs for RAG: A Smarter Approach to Contextual AI Appl...
All Things Open
 
PPTX
Artificial Intelligence Needs Community Intelligence - Sriram Raghavan, IBM R...
All Things Open
 
PDF
Don't just talk to AI, do more with AI: how to improve productivity with AI a...
All Things Open
 
PPTX
Open-Source GenAI vs. Enterprise GenAI: Navigating the Future of AI Innovatio...
All Things Open
 
PDF
The Death of the Browser - Rachel-Lee Nabors, AgentQL
All Things Open
 
PDF
Making Operating System updates fast, easy, and safe
All Things Open
 
PDF
Reshaping the landscape of belonging to transform community
All Things Open
 
PDF
The Unseen, Underappreciated Security Work Your Maintainers May (or may not) ...
All Things Open
 
PDF
Integrating Diversity, Equity, and Inclusion into Product Design
All Things Open
 
PDF
The Open Source Ecosystem for eBPF in Kubernetes
All Things Open
 
PDF
Open Source Privacy-Preserving Metrics - Sarah Gran & Brandon Pitman
All Things Open
 
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
All Things Open
 
Big Data on a Small Budget: Scalable Data Visualization for the Rest of Us - ...
All Things Open
 
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
 
Let's Create a GitHub Copilot Extension! - Nick Taylor, Pomerium
All Things Open
 
Leveraging Pre-Trained Transformer Models for Protein Function Prediction - T...
All Things Open
 
Gen AI: AI Agents - Making LLMs work together in an organized way - Brent Las...
All Things Open
 
You Don't Need an AI Strategy, But You Do Need to Be Strategic About AI - Jes...
All Things Open
 
DON’T PANIC: AI IS COMING – The Hitchhiker’s Guide to AI - Mark Hinkle, Perip...
All Things Open
 
Fine-Tuning Large Language Models with Declarative ML Orchestration - Shivay ...
All Things Open
 
Leveraging Knowledge Graphs for RAG: A Smarter Approach to Contextual AI Appl...
All Things Open
 
Artificial Intelligence Needs Community Intelligence - Sriram Raghavan, IBM R...
All Things Open
 
Don't just talk to AI, do more with AI: how to improve productivity with AI a...
All Things Open
 
Open-Source GenAI vs. Enterprise GenAI: Navigating the Future of AI Innovatio...
All Things Open
 
The Death of the Browser - Rachel-Lee Nabors, AgentQL
All Things Open
 
Making Operating System updates fast, easy, and safe
All Things Open
 
Reshaping the landscape of belonging to transform community
All Things Open
 
The Unseen, Underappreciated Security Work Your Maintainers May (or may not) ...
All Things Open
 
Integrating Diversity, Equity, and Inclusion into Product Design
All Things Open
 
The Open Source Ecosystem for eBPF in Kubernetes
All Things Open
 
Open Source Privacy-Preserving Metrics - Sarah Gran & Brandon Pitman
All Things Open
 
Ad

Recently uploaded (20)

PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Python basic programing language for automation
DanialHabibi2
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Ad

Nick Taylor - A Full Stack Web Framework for Deno

  • 1. Fresh: a full stack web framework for Deno Nick Taylor
  • 2. About Me ● Senior Software Engineer at OpenSauced ● From Montreal, Quebec, Canada ● I’m @nickytonline everywhere ● On the web at nickyt.co ● Streaming at nickyt.live ● Not a big fan of spiders
  • 4. What We’ll Cover ● What is Deno? ● Web Standards ● What is Fresh? ● Features ● Demo ● Questions
  • 6. What is Deno? ● Runtime for JavaScript, TypeScript & Web Assembly that uses V8 ● Built-in code formatter ● Built-in test runner ● Node.js interoperability via node specifiers ● npm interoperability via npm specifiers and CDNs
  • 7. What is Deno? For the Web, Deno runs pretty much anywhere ● Deno Deploy, edge-optimized and recommended by Deno ● Deno Deploy Subhosting, e.g. Netlify Edge Functions, Supabase Edge Functions ● Cloud platforms like fly.io and Railway ● serverless/container services ● self-hosted servers
  • 8. What is Deno? ● Deno was originally written in Go ● Go has a garbage collector and so does V8 ● Two garbage collectors === use Rust instead ● Nice side effect of Rust: WASM unlock 🦀
  • 11. Deno uses web standards ● import maps ● Fetch ● Request and Response ● etc. Web Standards
  • 12. Deno is a part of the Web-interoperable Runtimes Community Group (WinterCG). The group provides a space for JavaScript runtimes to collaborate on API interoperability Web Standards
  • 13. What is Fresh? Fresh is a full-stack web framework that runs on Deno. ● Server-side rendered (SSR) framework ● Just-in-time (JIT) rendering on the edge ● Provides TypeScript support out of the box ● Nothing to configure to get up and running
  • 14. What is Fresh? ● No JavaScript delivered by default ● Islands Architecture for client interactivity ● Preact (server-side and client-side) ● JSX support (thanks Preact and TypeScript!)
  • 15. deno run -A -r https://fresh.deno.dev
  • 20. Features ● Static files ● Routes & Routing ● Data Fetching ● Middleware ● Error pages
  • 21. Features ● Styling ● Islands ● Signals ● Partials
  • 23. Static Files ● All static assets reside in the `/static` folder ● No caching headers by default for static assets ○ Exceptions: src and srcset attributes on <img /> and <source/> elements ● Use the asset helper to automatically cache for a year
  • 26. Routes & Routing ● 3 kinds of routes: ○ Handler route (API route) ○ Component route (Pages) ○ Hybrid route (handler and component) ■ form that POSTs back, ■ search page that GETs search results
  • 27. Routes & Routing ● Routes can be dynamic https://fresh.deno.dev/docs/concepts/routing
  • 29. Data Fetching Handler routes and Hybrid routes handle data fetching
  • 30. Data Fetching ● For handler routes (APIs), export function that returns a response
  • 31. Data Fetching ● For hybrid routes, define functions for actions in an exported variable called handler ● Name async functions after HTTP verbs: GET, POST etc.
  • 34. ● Has to be named _middleware.ts. ● Resides in the /routes folder ● Multiple middlewares are supported Middleware
  • 35. Middleware Root middleware runs 1st Movie subfolder middleware runs 2nd
  • 36. Middleware Middleware 1 Middleware 2 http://localhost:8000/movies/1
  • 38. Error Pages ● Create custom error pages: 404, 500 etc. ● Must be in the root of the /routes folder
  • 40. Error Pages ● For a dynamic route, call ctx.renderNotFound() to render the 404 page if page does not exist
  • 43. Styling ● Twind, a server-side rendered implementation of Tailwind ● Tailwind ● Modern CSS on its own is pretty awesome ● Expect innovation here from userland
  • 46. Islands “The general idea of an “Islands” architecture is deceptively simple: render HTML pages on the server, and inject placeholders or slots around highly dynamic regions. These placeholders/slots contain the server-rendered HTML output from their corresponding widget. They denote regions that can then be "hydrated" on the client into small self-contained widgets, reusing their server-rendered initial HTML.” https://jasonformat.com/islands-architecture – Jason Miller
  • 47. Islands ● Must reside in /islands folder
  • 49. How do we revive an island?
  • 50. How do we revive an island? ● A script of type application/json holds the initial state of any islands
  • 51. How do we revive an island?
  • 52. How do we revive an island?
  • 53. How do we revive an island?
  • 54. ● Since Fresh uses Preact, signals are available on the client-side. ● Alternative to useState, useReducer… Signals
  • 55. “At its core, a signal is an object with a .value property that holds a value. This has an important characteristic: a signal's value can change, but the signal itself always stays the same” – Preact Signals documentation Signals
  • 59. ● Enables client-side routing to give a snappier feel to your app ● Requires an HTML attribute f-client-nav on a container element, e.g. <body /> ● Wrap main content with a <Partial /> component Partials
  • 61. ● Can do more granular partials if you want to ● See the documentation on Partials Partials
  • 67. Resources ● Fresh Website ● Fresh: a new full stack web framework for Deno with Luca Casonat o ● Fresh 1.5: Partials, client side navigation and more ● Fresh 1.6: Tailwind CSS plugin, simplified typings and more ● Islands Architecture ● A Gentle Introduction to Islands ● Installing Deno ● Preact ● Preact Signals
  • 68. Resources ● Installing Deno ● Preact ● Preact Signals ● WTF is JSX? ● What is Deno? ● TypeScript Language ● Import maps ● Fetch API ● revive() function ● WinterCG
  • 69. Resources ● Request ● Response ● Twind ● Deno: node: specifiers ● Deno: npm via CDNs ● Deno: npm: specifiers ● import maps
  • 70. slide deck available at nickyt.co/slides/ato24
  • 71. Stay in touch! ● @nickytonline everywhere ● nickyt.co ● nickyt.live ● github.com/nickytonline

Editor's Notes

  • #1: Hi everyone! Today we’re going to talk about Fresh, a full stack web framework for Deno
  • #4: We’ll go over what Fresh is, discuss web standards and then we’ll dig into the features of Fresh. After that, there will be a short demo and then we can move on to questions and comments. By the end of the talk, you should have a good understanding of how all the pieces of Fresh work.
  • #5: Created by the creator of Node.js, Ryan Dahl.
  • #9: Just a quick congrats to the Deno team. Deno 2.0 was released on Oct 9th. Pretty awesome support for npm packages, speed improvements, and all kinds of goodies. Definitely worth checking out.
  • #10: Alright, let’s talk web standards
  • #11: Deno uses web standards. For example, import maps, fetch, request and response etc.
  • #12: As part of web standards, Deno is a part of the WinterCG, the Web-interoperable Runtimes Community Group. It’s a space to collaborate on API interoperability for JavaScript runtimes. Companies like Netlify, Vercel, and Cloudflare are also a part of the WinterCG
  • #14: If you’re unfamiliar with the amazing Preact project, it’s a a fast and smaller alternative to React with the same modern API. It only gets a mention here for now, but we’ll dig into what islands architecture is a little later in the talk. Because Fresh uses Deno which runs V8, you can leverage the same debugging tools as Node.js, and by going with Preact, there is already tonnes of IDE tooling for JSX.
  • #15: Assuming you already have Deno installed, getting Fresh installed is pretty quick. Just run the command you see on the slide.
  • #16: The installation is pretty quick and you have a couple of options. You can choose opt for a styling library or not. If you do, you can choose between Tailwind or Twind, server-side rendered Tailwind. If you’re using VS Code, like many probably are, you can choose to install the VS Code integration via the Deno VS Code extension, and that’s pretty much it.
  • #17: Although Deno can read package.json files for Node.js compatibility, Fresh uses the Deno way by default which means a deno.json file instead of a package.json. Similar to npm’s scripts, Deno has tasks. So instead of npm run start, you’d run deno task start.
  • #18: The deno.json has an imports section, similar to dependencies and dev dependencies in a package.json file, however, in Deno, all imports are URLs. So either https:, npm:, jsr: or any other valid qualifier for a URL. It’s out of scope for the talk, but the imports property is an import map. There’s a link in the resources section of the slide deck if you want to read up more on import maps.
  • #19: Alright, so let’s dig into some Fresh of Fresh
  • #23: All static assets can be found in the static folder Static assets aside from image and source tags do not have cache headers set on them. You can set cache headers manually or you can use the built in asset helper to automatically cache an asset for a year.
  • #24: Here’s an example of the asset helper in action. It generates a unique URL whic is composed of the asset file path followed by a querystring with one key underscore frsh underscore c with a value that is the build ID from the deployment
  • #26: There are three kinds of routes: there’s the handler route, component route and hybrid route. Handler routes are for APIs, component routes are for pages, and hybrid routes are for pages that require handler routes. For example a login page or a search page.
  • #27: Like in other frameworks, routes can also be dynamic. You can see in the table here the many types of file-based routing patterns that are supported. Fresh only supports server-side rendering so there is no concept of something like getStaticPaths in Next.js or Astro since pages are never statically generated.
  • #30: For a handler route, all that is required is exporting a function that takes two arguments: a request and a context and returns a response
  • #31: For hybrid routes, define functions for actions in an exported variable called handler Name the async functions in the handler object after HTTP verbs. For example GET. Whereas the handler route in the previous example returns a response, typically in a hybrid route, you’ll want to return the result of the context render method.
  • #32: Think of context render as passing in server-side rendered props to the page being rendered. If you’ve used Next.js’ pages router, it’s not the same thing, but it is a similar idea to getServerSideProps but it returns rendered content directly instead of props. Looking at the example on the slide, one thing to note about props in Fresh is that it’s not props dot movies. The props from context dot render are always in the props dot data property. So for example, the array of movies prop is actually props dot data, not props dot data dot movies.
  • #34: Let’s talk middleware. Again like other frameworks, Fresh supports middleware. Middleware files are named underscore middleware dot ts and need to reside in the routes folder. Multiple middlewares are supported. Although Deno encourages you to use TypeScript, you could write the middleware as a JavaScript file.
  • #35: Let’s look at an example. Say I navigate to slash movie slash top gun. Since we’re hitting the dynamic movie route, that means we’re using two middlewares. One in the root of the routes folder and one in the movie subfolder. In the case of multiple middlewares, the least specific one runs first. In our example, that means the root middleware runs first. It adds an x dash conference header with the value Node Congress 2023. Then the second middleware runs, the movie one. It adds an x dash movie dash page header along with a cache header that caches the page for 60 seconds.
  • #36: So in our movie route example, the headers set in the two middlewares get set on the response as expected.
  • #38: Like other frameworks, you can define custom error pages. For example, the current slide shows a custom 404 page. These are component routes but they can have special props passed in. In the case of the 404 page, you have access to the Unknown Page Props when the page is rendering. The Unknown Page Props gives you access to things like the URL of the page that was not found.
  • #39: Like other frameworks, you can define custom error pages. For example, the current slide shows a custom 404 page. These are component routes but they can have special props passed in. In the case of the 404 page, you have access to the Unknown Page Props when the page is rendering. The Unknown Page Props gives you access to things like the URL of the page that was not found.
  • #40: When we were discussing data fetching, I mentioned that we need to return the result of context dot render for hybrid routes. That still holds, but if you’re on a page that is associated with a dynamic route and the page being loaded does not exist, return context dot render not found instead. Context dot render not found will then pass the unknown page props to the 404 page.
  • #41: When we were discussing data fetching, I mentioned that we need to typically return the result of context dot render for hybrid routes. That still holds, but if you’re on a page that is associated with a dynamic route and the page being loaded does not exist, return context render not found instead. Context render not found will then pass the unknown page props to the 404 page.
  • #43: So what about styling? When Fresh first came out there was no build step. You could use Vanilla modern CSS (pretty good) with the asset helper, but for Tailwind fans, TWind was the only option. The team realized that a build step can be useful, so now Tailwind is one of the default options. As Fresh gains more traction, expect to see innovation from user land for the styling story. That said, I’d love to see scoped CSS on a per page/component level, but maybe they’ll just wait for native scoped CSS.
  • #44: Alright, let’s talk about islands. What is an island anyway?
  • #45: I mentioned it briefly when describing the architecture of Fresh, but we’ll dig into islands architecture a little more now. The long story short is it enables pockets of interactivity in your site or application.
  • #46: I’ll leave this up for a little bit, but Jason Miller, one of the folks alongside Katie Sylor-Miller coined the term islands architecture. It’s fitting that Jason is one of the folks that coined this term as he’s also the creator of Preact. In islands architecture the goal is to ship mainly static HTML and then mark certain regions of the document object model, the DOM, as available to hydrate for interactive, or to use Fresh’s terminology, revive. When a page with islands loads, only the JavaScript for those islands is loaded.
  • #47: Fresh serves zero JavaScript to the client by default. So how to we enable client side interactivity? Fresh has two component folders: components and islands. Components in the components folder will render server-side only, even if you add client-side interactivity to them. Components in the islands folder will render server-side as well and once the page loads, the client-interactivity will be revived.
  • #48: Let’s look at a classic interactive component. A counter. It has a couple of buttons. If you click +1 it increments the counter and if you click -1 it decrements the counter.
  • #50: This gets rendered server-side by Fresh.
  • #51: When the page loads, Fresh injects some JavaScript to revive the islands. A function literally called revive loads any number of island component definitions along with the last argument being the props for all island components.
  • #52: In the previous example there was only one island, but if there was more than one island, how does Fresh map the initial state correctly?
  • #53: We talked about denoting interactive regions in the DOM when talking about islands architecture. Island components in Fresh will get server-side rendered with HTML comments surrounding them. The comment is prefixed with F R S H dash followed by the name of the component, colon and then the array index of where the island component state lives in the initial state for all islands that was initially loaded. It doesn’t matter how many different island components there are or how many instances of each. The array index will be incremented in each HTML comment based on the order of the islands in the DOM. One thing to note is that this is an implementation detail. You’ll never need to manage this yourself. I just find it useful to understand the underlying technology.
  • #54: Signals amirite? All the rage these days. Since Fresh uses Preact, it can leverage Preact’s signal implementation as an alternative to state hooks.
  • #55: We’re not going to do a deep dive on Signals, so I recommend checking out the Preact Signals documentation and for signals in general, any talk or blog post about signals from my old co-worker Ryan Carniato is a pretty safe bet.
  • #59: With Partials, you can mark areas in your page that change on navigation. Only those regions will be updated by Fresh. And if you’re using islands, their state remains intact.
  • #60: When you navigate to a page it
  • #65: When Fresh first launched, I hung out with the creator Luca Casonato. Although there have been some additions to the framework since we hung out, this is still a really great deep dive into Fresh.