惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
L
Lohrmann on Cybersecurity
Simon Willison's Weblog
Simon Willison's Weblog
P
Proofpoint News Feed
P
Privacy International News Feed
The Hacker News
The Hacker News
AWS News Blog
AWS News Blog
S
Securelist
P
Proofpoint News Feed
Recent Announcements
Recent Announcements
GbyAI
GbyAI
B
Blog RSS Feed
A
About on SuperTechFans
C
CXSECURITY Database RSS Feed - CXSecurity.com
Y
Y Combinator Blog
Microsoft Azure Blog
Microsoft Azure Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Cyberwarzone
Cyberwarzone
I
Intezer
T
Tor Project blog
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
Recorded Future
Recorded Future
aimingoo的专栏
aimingoo的专栏
Cisco Talos Blog
Cisco Talos Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
W
WeLiveSecurity
D
DataBreaches.Net
U
Unit 42
Project Zero
Project Zero
Martin Fowler
Martin Fowler
V
V2EX
The Last Watchdog
The Last Watchdog
Security Archives - TechRepublic
Security Archives - TechRepublic
C
Cisco Blogs
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V2EX - 技术
V2EX - 技术
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Threat Research - Cisco Blogs
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Tenable Blog
F
Full Disclosure
T
The Exploit Database - CXSecurity.com
H
Heimdal Security Blog
Latest news
Latest news
Webroot Blog
Webroot Blog

Deno

Deno 2.8 | Deno Claw Patrol: an open-source security firewall for agents | Deno Fresh 2.3: Zero JS by default, View Transitions, and Temporal support | Deno Deno 2.7: Temporal API, Windows ARM, and npm overrides | Deno Build a dinosaur runner game with Deno, pt. 6 | Deno Build a dinosaur runner game with Deno, pt. 5 | Deno Deno Deploy is Generally Available | Deno Introducing Deno Sandbox | Deno Build a dinosaur runner game with Deno, pt. 4 | Deno Build a dinosaur runner game with Deno, pt. 3 | Deno Build a dinosaur runner game with Deno, pt. 2 | Deno React / Next.js Denial-of-Service Vulnerability: Deno Deploy users protected | Deno Deno 2.6: dx is the new npx | Deno Build a dinosaur runner game with Deno, pt. 1 | Deno React Server Functions / Next.js Vulnerability: Deno Deploy users protected | Deno My highlights from the new Deno Deploy | Deno Deno's Other Open Source Projects | Deno How Deno protects against npm exploits | Deno Help Us Raise $200k to Free JavaScript from Oracle | Deno Deno 2.5: Permissions in the config file | Deno Fresh 2.0 Graduates to Beta, Adds Vite Support | Deno Deno 2.4: deno bundle is back | Deno JavaScript™ Trademark Update | Deno What's coming to JavaScript | Deno A brief history of JavaScript | Deno Reports of Deno's Demise Have Been Greatly Exaggerated | Deno An Update on Fresh | Deno How Plaid migrated 100 services to a new database platform 5x faster with Deno | Deno Deno 2.3: Improved deno compile, local npm packages, and more | Deno Add JSR packages with pnpm and Yarn | Deno Zero-config Debugging with Deno and OpenTelemetry | Deno Exploring Art with TypeScript, Jupyter, Polars, and Observable Plot | Deno Deno v Oracle Update 3: Fighting the JavaScript Trademark | Deno Build a custom RAG AI agent in TypeScript and Jupyter | Deno How to get deep traces in your Node.js backend with OTel and Deno | Deno toranoana.deno #20 登録受付中(2025年3月14日) | Deno Node just added TypeScript support. What does that mean for Deno? | Deno The Dino 🦕, the Llama 🦙, and the Whale 🐋 | Deno Publish a lint rule, get a prize | Deno Deno 2.2: OpenTelemetry, Lint Plugins, node:sqlite | Deno If you're not using npm specifiers, you're doing it wrong | Deno How Deno's documentation is evolving | Deno Oracle justified its JavaScript trademark with Node.js—now it wants that ignored | Deno Introducing the JSR open governance board | Deno Intro to Wasm in Deno | Deno Announcing OpenAI on JSR | Deno Deno in 2024 | Deno Goodbye WinterCG, welcome WinterTC | Deno Build a SolidJS app with Deno | Deno Run your Next.js SSR app on Deno Deploy | Deno Solve Advent of Code 2024 with Deno and Win Prizes! | Deno Deno v. Oracle: Canceling the JavaScript Trademark | Deno Deno 2.1: Wasm Imports and other enhancements | Deno Build a Typesafe API with tRPC and Deno | Deno Self-contained Executable Programs with Deno Compile | Deno Build a Database App with Drizzle ORM and Deno | Deno Introducing your new JavaScript package manager: Deno | Deno Announcing Growthbook on JSR | Deno Build an Astro site with Deno | Deno How to convert CommonJS to ESM | Deno Announcing Deno 2 | Deno The Final Touches: What’s New In v2.0.0-rc.10 | Deno Announcing Stable V8 Bindings for Rust | Deno Deno 2.0 Release Candidate | Deno Secure, efficient private npm registries with Cloudsmith and Deno | Deno Painting the Plane as We Fly It: Designing JSR | Deno Introducing Web Cache API support on Deno Deploy | Deno Deno 1.46: The Last 1.x Release | Deno Protect your cloud spend with new Deno Deploy spend limits | Deno What we got wrong about HTTP imports | Deno Benchmarking AWS Lambda Cold Starts Across JavaScript Runtimes | Deno Announcing Supabase on JSR | Deno Deno 1.45: Workspace and Monorepo Support | Deno Introducing KV Backup for Deno Subhosting | Deno A Gentle Intro to TypeScript | Deno Announcing Hono on JSR | Deno How We Made the Deno Language Server Ten Times Faster | Deno How the Guardian uses Deno to audit accessibility and performance across their 2.7 million articles | Deno Introducing More Flexible Domain Association for Deno Subhosting | Deno The stabilization process of the Standard Library has begun | Deno Deno 1.44: Private npm registries, improved Node.js compat, and performance boosts | Deno How we built a secure, performant, multi-tenant cloud platform to run untrusted code | Deno The Deno Standard Library is now available on JSR | Deno How to document your JavaScript package | Deno Your Low Code Solution Needs an Escape Hatch | Deno Deno 1.43: Improved Language Server performance | Deno How Slack used Deno to save months of engineering effort in launching their new platform | Deno JSR Is Not Another Package Manager | Deno Announcing the Hookdeck SDK on JSR | Deno Announcing the Neon Serverless Driver on JSR | Deno An intro to TSConfig for JavaScript Developers | Deno How we built JSR | Deno How Netlify used Deno Subhosting to build a successful edge functions product | Deno Introducing Simpler Project Creation in Deno Deploy | Deno Deno 1.42: Better dependency management with JSR | Deno Introducing deployctl, the command line interface for Deno Deploy | Deno Introducing JSR - the JavaScript Registry | Deno How to add Monaco to a Next.js app and securely run untrusted user code | Deno Survey Results and Roadmap | Deno Deno 1.41: smaller deno compile binaries | Deno
Fresh 1.4 – Faster Page Loads, Layouts and More | Deno
Marvin Hagem · 2023-08-16 · via Deno

In this cycle we’ve focused on the overall developer experience of making it easier to use shared layouts, route-specific islands and more in Fresh.

Remember: you can start a new Fresh project by running deno run -A -r https://fresh.deno.dev or update an existing project by running deno run -A -r https://fresh.deno.dev/update . in your project folder.

  • Faster page loads with ahead-of-time compilation
  • Custom html, head and body tags
  • Layouts
  • Async layouts and async app wrapper
  • Quicker typing with define functions
  • Organise your code with Route Groups
    • Colocated islands, components and more
  • What’s on the horizon?

Faster page loads with ahead-of-time compilation

So far, Fresh has always compiled assets on the fly. This has served us well so far, as it enables lightning fast deployments with no build step, but we realised just-in-time (=JIT) rendering with large islands was noticeably slower. We arrived at a pre-compile solution that results in assets being served ~45-60x faster for a cold start of a serverless function, with minimal impact on deployment times. The savings depend on the size of the island, but even for small ones the improvements are very visible.

Here is a demonstration of the different techniques on the Fresh documentation site. The search box is a small island which weights around ~30kB.

The search box island revives nearly instantaneously with ahead of time compiled assets whereas it took 4.28s with JIT compilation.

Locally, when running the development server, Fresh will always use JIT compilation so that your sever can respond to API as soon as possible and doesn’t have to wait for asset compilation to finish.

You can opt into AOT compilation for deployments by following the ahead-of-time builds guide. Running deno task build will create a _fresh folder which holds all the generated assets.

Custom html, head and body tags

A tricky aspect in previous versions was setting the lang attribute on the <html>-tag. Up until now Fresh created the outer HTML structure up to the <body>-tag internally and you’d need to apply workarounds like creating a custom render function to modify the lang attribute.

await start(manifest, {
  
  
  render: (ctx, render) => {
    ctx.lang = "de";
    render();
  },
});

After thinking about this for a while we realised that we could simplify Fresh quite a bit by allowing you to render the HTML document yourself. So we did exactly that. With Fresh 1.4 you can set the <html> , <head> and <body>-tag directly on the server.


import { AppProps } from "$fresh/server.ts";

export default function App({ Component }: AppProps) {
  return (
    <html lang="de">
      <head>
        <title>My Fresh App</title>
      </head>
      <body>
        <Component />
      </body>
    </html>
  );
}

To make upgrading from older Fresh versions easier, we added some logic to detect whether an <html>-tag was rendered or not. If none was rendered, we fall back to wrapping the html with the internal template like in past Fresh versions.

Layouts

A common aspect of building web applications is that many parts of the layouts are shared across routes. Think of the Header or Footer of a website which is the same component across routes. Previously, you could do that in routes/_app.tsx, but there was no way to go beyond that. Creating a shared layout for some sub routes in your app required extracting the code into a component and importing it into all routes manually.

In Fresh 1.4, we added support for _layout files, which can be described as a route local app wrapper. They can be put in any route folder and Fresh will detect all the layouts that match and stack them on top of each other.

routes/
  _app.tsx
  _layout.tsx
  page.tsx      

  sub-route/
    _layout.tsx 
    index.tsx   
    about.tsx   

A _layout file looks very similar to a route file or the app wrapper. It uses the Component prop to continue rendering further layouts or the final route file.


import { LayoutProps } from "$fresh/server.ts";

export default function MyLayout({ Component }: LayoutProps) {
  return (
    <div class="my-layout">
      <h2>This is rendered by a layout</h2>
      <Component />
    </div>
  );
}

But there are times where you don’t want to inherit layouts or even the app wrapper, so we also added a way for you to opt-out of that.

export const config: RouteConfig = {
  skipAppWrapper: true, 
  skipInheritedLayouts: true, 
};

Thanks to Michael Gearhardt for kicking off the work on this feature!

Async layouts and async app wrapper

Once we had landed support for layouts, we wondered what would happen if we made them the same as a route? Could we allow async layout components too? It would surely reduce mental load by making route components and layout components behave the same. After a bit of coding, it turned out we can. So this Fresh release brings you not just _layout components, but also async layouts!

export default async function Layout(req: Request, ctx: LayoutContext) {
  const person = await fetchSomeData();

  return (
    <div>
      <h1>Hello {person.name}</h1>
      <ctx.Component />
    </div>
  );
}

And while we’re at it, why not make the app wrapper async too? With Fresh 1.4, all layouts behave the same. The only special case are Routes because they’re at the end of the rendering chain and therefore don’t have a ctx.Component property.

Quicker typing with define functions

With the introduction of async route components we received some feedback that the function definition becomes a bit “wordy” with it needing so many keywords.

export default async function Page(req: Request, ctx: RouteContext) {
  
}

And looking at that we share those concerns. I noticed that it always took me a bit of time to type that out. Sure, one could add a custom snippet in your editor to create that boilerplate, but that seemed more of a workaround than a proper solution.

So we spent some time bouncing a few ideas back and forth until we came up with the concept of define* helper functions. They don’t contain any logic, but they provide autocompletion hints to editor out of the box, without having to define the types yourself.


export default defineRoute(async (req, ctx) => {
  
}

If you look at the two snippets, there doesn’t seem to be much of a difference. But when you type them out in your editor, you’ll notice that the latter is much quicker to type.

The following define helper functions are available:

  • defineRoute for creating routes
  • defineLayout for creating layouts
  • defineApp for creating the app wrapper.

Organise your code with Route Groups

Normally, nested folders inside the routes/ directory are mapped directly to URLs. However, with bigger projects there are often scenarios where you want to group files and not have that affect the structure of the URL.

Route groups make this possible. A route group is a folder inside routes/ whose name is surrounded by parenthesis like (my-group). This also allows you to have different _layout and _middleware files for routes on the same segment.

routes/
  (marketing)/
    _layout.tsx
    about.tsx  

  (blog)/
    _layout.tsx
    archive.tsx 

Colocated islands, components and more

When the name of a route group folder starts with an underscore, like (_components), Fresh will ignore that folder and it’s effectively treated as private. This means you can use these private route folders to store components related to a particular route. The one special name is (_islands) which tells Fresh to treat all files in that folder as an island.

routes/
  shop/
    (_components)/  
      Section.tsx

    (_islands)/     
      Cart.tsx

    index.tsx

Combined together, this gives you the ability to organise your code on a feature basis and put all related components, islands or anything else into a shared folder.

What’s on the horizon?

There were lots more features in the works, that didn’t make the cut because they need a bit more time to cook. In particular, we’re working on overhauling our plugin system to make it easier to understand and more powerful. The PR to add support for view transitions is coming along nicely and with that we’re exploring how to add spa-like client navigation to Fresh. Another area we’ve been looking at are styling solutions like UnoCSS, using tailwind directly and other solutions.

Like in the past month you can follow this months iteration plan on GitHub.

Did you know? Deno 1.36 was just released.

Be sure to check out the release notes for Deno 1.36, which comes with improved security controls, testing, benchmarking, and more.