deno reactjs,Trying out Deno Fresh: new Fast Framework for Web | Rodney Lab

🦖 Deno and Fresh #

In this post we are trying out Deno Fresh. Deno is a JavaScript runtime like, forexample, Node or Bun. A JavaScript runtime is just an environment in which you can run the JavaScriptcode. Others are the browser and Cloudflare Workers. Deno, similarly to Bun, is one of the newer runtimesand has TypeScript support out of the box. Fresh is a web framework for building fast sites. Like Astro JS, it is inspired by the Islands of interactivity paradigm (more on thatlater).

That’s all the introductions out of the way then! This post will be a kind of “kicking the tyres” look at Fresh rather than an in-depth probe into its features. To help we builtout a basic site and also include some of tips I picked up getting started with Deno Fresh.

🍋 What is Fresh about Fresh? #

There is no shortage of web frameworks so a good question to ask is when you might reach forfresh. Based on the Island technology, I would say try it on a site which does not have a lot ofinteractivity, for example. Or even a site which has interactivity only in sparse, independentparts of the pages. Fresh might make the page faster, bringing user experience as well as SEObenefits.

Islands are units of the page where we can opt to add interactivity. They can be a singlecomponent or a group of components — whatever makes sense for the application.

For example, you might have an e-commerce site or even a basic blog with only certain elementsthat need JavaScript. On these sites often the header and footer and many other elements will notneed to be interactive. You could include elements with animation and transitions handled by CSSin this category. Customer feedback buttons, likes counters and components pulling in the latestcomments are elements you might make islands. Apps with these “sprinkled on”interactive parts are the kind of app which Fresh should suit well.

How is Fresh different to Astro? #

They both support TypeScript out of the box and use Islands paradigm. Though some differences arewhile Astro supports Svelte , Preact, React, Vue as well as other frameworks. As it stands Fresh only supports Preact— an optimised React alternative, which uses the same API as React.

At the time of writing, you cannot use the full collection of NPM packages with Deno and thereforeFresh. That is changing though and both ES Module and CommonJS based NPM packages will get support in a future version .

🧱 How to Spin up a Fresh Fresh App #

You need to have Deno CLI setup on your system to get running. If you are on a Mac and haveHomebrew, run:

brew install deno

On Linux and in most other cases, you can run a shell install script from the Terminal:

curl -fsSL | sh

Then you can create a new fresh project with:

deno run -A -r my-fresh-fresh-appcd my fresh-fresh-appdeno task start

You get to choose it you want Tailwind styling and TypeScript in the interactive scaffoldingscript. You new app will be running at http://localhost:8000/ .

😯 How Does Fresh Code Look? #

For a complete getting started guide, check out the Fresh docs , we’ll just skim over a couple of details here. Fresh uses file-based routing likeRemix or Astro. So routes/index.tsx corresponds to the path. You can add meta (e.g. SEO) and rel tags to a Head componenton pages. Here is the routes/index.tsx file, which should look familiarif you already know React:

routes/index.tsxtsx1 /** @jsx h */2 import { Fragment, h } from "preact";3 4 import { Head } from "$fresh/runtime.ts";5 import BannerImage from "../components/BannerImage.tsx";6 import Video from "../islands/Video.tsx";7 8 export default function Home() {9 return (10 11 12 13 14 15 16 17 18 19 20 Trying Deno Fresh 🍋21 25 26 27 28 FRESH29 Fresh 🍋 new framework!30 31 32 33 );34 }Trying out Deno Fresh: screenshot of demo site shows heading fresh with test Fresh 🍋 new framework! belowTrying out Deno Fresh: Demo SiteIsland Example #

The island hydration works a little differently to Astro; you put any island components in the islands folder. To test this out, I just added a potentially privacy enhancing feature where you have toclick to accept loading a video from a social video sharing service:

islands/Video.tsx — click to expand code.islands/Video.tsxtsx/** @jsx h */import { h } from "preact"; import { useState } from "preact/hooks";import { Button } from "../components/Button.tsx"; export default function Video() {const [showVideo, setShowVideo] = useState(false);return ({!showVideo ? ( {setShowVideo(true);}}>📼 Click to enable YouTube video playback) : ()}Fireship: A fresh new web framework is out!);}Browser not supported 😢 Trying out Deno Fresh: Demo App💚 What I Liked #Deno CLI tooling has a code formatter and linter (commands: deno fmt, deno lint), so no need to add and Prettier and ESLint toyour new projects,there is no build step and code renders just in time on the edge,there is no extra markup within components for handling island hydration. This should make itquicker to try out an existing React project.🧐 What I Need to Explore More #Styling: I wanted to go for vanilla CSS and stuck all the styles in a global.css file in the static folder. I then linked the stylesheet from alink rel= tag. Didn’t find docs on if there is a fresher wayof doing this, or if you can add scoped styles something like the Remix solution for vanilla CSS . A bonus would be vanilla-extract support in Fresh.Dependencies: I didn’t add any extra packages — had a quick scan for something to lazy load images (like vanilla-lazyload) or for creating responsiveimage source sets but did not find anything. However, I should just be able to use the NPMvanilla-lazyload in the new version.I haven’t looked into testing. There is, however, a testing module in the Deno tooling , which will be exciting to explore.🗳 Poll #Have you tried Deno in an app or edge function?🙌🏽 Trying out Deno Fresh: Wrapping Up #

We have taken a whistle-stop tour of the new Deno Fresh web framework. In particular, we saw:

what fresh does differently,when you might reach for fresh,as well as how to spin up a new Fresh project.

Check out the Fresh docs for further details. Get in touch if you would like to see more contenton Fresh. Also keen to hear how you might use it in your own projects. Take a look at the fulldemo site code on the Rodney Lab GitHub page . I hope you found that useful and am keen to hear about possible improvements.

🏁 Trying out Deno Fresh: Summary #What makes Deno Fresh fast? #Deno Fresh is a new web framework.It uses Deno to build server side generated site quickly. The generated sites as well as the tooling are quick. You write your site pages and components in Preact. This is an optimised version of React which explains where some of the speed come from. On top, Fresh ships zero JavaScript by default.You have to enable JavaScript in components which need it (called islands).This limits JavaScript to isolated parts of the page, reducing the number of bytes sent to a browser.Islands together with Preact optimisations help explain Fresh’s speed.How is Fresh different to Astro #Both Astro and Deno Fresh are architected on the Island paradigm. Both have fast, modern tooling with out-of-the-box TypeScript support. Currently Fresh limits you to writing your app in Preact (an optimised version of React which shares its APIs).By contrast, you can author Astro apps in Svelte, React, Preact, Vue and other frameworks. Astro is compatible with most node environments making your site easily deployable to a number of hosting providing. Fresh runs in Deno which is among the fastest JavaScript runtime environments. Astro lets you create static (Static Site Generation, or SSG) sites as well as SSR, while Fresh offers Server Side Rendered apps.Can you use NPM packages in Deno apps #At the time of writing, you are limited to the Deno ecosystem when looking for packages to add to your apps.However, that is all about to change. Deno have announced support for NPM packages in a future release. You will be able to source NPM packages by using an `npm:` prefix on the import URL, followed by the package name. This will work for ES Modules-based and CommonJS-based NPM packages.🙏🏽 Trying out Deno Fresh: Feedback #

Have you found the post useful? Would you prefer to see posts on another topic instead? Get intouch with ideas for new posts. Also if you like my writing style, get in touch if I can writesome posts for your company site on a consultancy basis. Read on to find ways to get in touch,further below. If you want to support posts similar to this one and can spare a few dollars, eurosor pounds, then please consider supporting me through Buy me a Coffee.

Finally, feel free to share the post on your social media accounts for all your followers who willfind it useful. As well as leaving a comment below, you can get in touch via @askRodneyon Twitter and also askRodney on Telegram . Also, see further ways to get in touch with Rodney Lab. I post regularly on Astro as wellas SvelteKit. Also subscribe to the newsletter to keep up-to-date with our latest projects.

新建react项目deno空压机deno 后端框架deno官网deno 后端deno 入门deno 替代 nodejsdeno 热更新deno reactjs山上养溜达鸡图片尚云祥尚氏形意拳文化夸赞女人有气质和内涵的句子何家劲朱重八电视剧真我x7pro手机的缺点牡丹 花王猫眼vip软件下载2022烟的种类及价格图片大全张嘉倪顺嫔就是香妃吗人际交往中,自我表露共有几个层次?奶油面包片的做法大全