ayame113andLuca Casonato 7b35cb07d4 feat: preloading JavaScript files (#1189)
close #1187

## points

- use `<link rel="modulepreload">` tag and `Link: rel="modulepreload"`
header to preload dependencies
- No preloading at all for pages that don't use JavaScript at all.
- Information about preloading is delivered only when the JS file has
already been built. If the JS file hasn't finished building, it will
respond without preload information instead of waiting for the build and
then returning the HTML.

## performance comparison

I've deployed this branch to https://fresh-module-preload.deno.dev/ so
you can try it out and see how it behaves.

When I accessed [fresh.deno.dev](https://fresh.deno.dev/) and
[fresh-module-preload.deno.dev](https://fresh-module-preload.deno.dev/)
20 times each and measured the DOMContentLoaded time, it was 24% faster
(157.3ms -> 118.95ms) in my environment (Nagano City, Japan).

<details>
<summary>Actual measured data</summary>

(Don't forget to check `Disable Cache` in devtools)

 | afeter (ms) | before (ms)
-- | -- | --
0 | 180 | 152
1 | 82 | 144
2 | 78 | 186
3 | 156 | 196
4 | 88 | 211
5 | 85 | 123
6 | 162 | 209
7 | 154 | 110
8 | 86 | 175
9 | 135 | 109
10 | 183 | 117
11 | 115 | 159
12 | 99 | 173
13 | 83 | 131
14 | 82 | 142
15 | 135 | 160
16 | 120 | 125
17 | 148 | 152
18 | 118 | 229
19 | 90 | 143
average | 118.95 | 157.3

</details>

## screen shots


![image](https://github.com/denoland/fresh/assets/40050810/c8f6d46b-77da-4e20-b29c-3b0219907872)


![image](https://github.com/denoland/fresh/assets/40050810/3159904c-07f0-45ee-a9ca-7bed35a292ca)

---------

Co-authored-by: Luca Casonato <hello@lcas.dev>
2023-06-01 11:18:28 +10:00
2022-04-24 13:12:38 +02:00
2023-05-19 14:21:50 +10:00
2023-05-18 21:20:48 +10:00
2021-05-08 02:07:24 +02:00
2022-09-07 09:36:23 +00:00

Documentation | Getting started | API Reference

fresh

the fresh logo: a sliced lemon dripping with juice

Fresh is a next generation web framework, built for speed, reliability, and simplicity.

Some stand-out features:

  • Just-in-time rendering on the edge.
  • Island based client hydration for maximum interactivity.
  • Zero runtime overhead: no JS is shipped to the client by default.
  • No build step.
  • No configuration necessary.
  • TypeScript support out of the box.
  • File-system routing à la Next.js.

📖 Documentation

The documentation is available on fresh.deno.dev.

🚀 Getting started

Install Deno CLI version 1.25.0 or higher.

You can scaffold a new project by running the Fresh init script. To scaffold a project in the deno-fresh-demo folder, run the following:

deno run -A -r https://fresh.deno.dev deno-fresh-demo

Then navigate to the newly created project folder:

cd deno-fresh-demo

From within your project folder, start the development server using the deno task command:

deno task start

Now open http://localhost:8000 in your browser to view the page. You make changes to the project source code and see them reflected in your browser.

To deploy the project to the live internet, you can use Deno Deploy:

  1. Push your project to GitHub.
  2. Create a Deno Deploy project.
  3. Link the Deno Deploy project to the main.ts file in the root of the created repository.
  4. The project will be deployed to a public $project.deno.dev subdomain.

For a more in-depth getting started guide, visit the Getting Started page in the Fresh docs.

Adding your project to the showcase

If you feel that your project would be helpful to other fresh users, please consider putting your project on the showcase. However, websites that are just for promotional purposes may not be listed.

To take a screenshot, run the following command.

deno task screenshot [url] [your-app-name]

Then add your site to showcase.json, preferably with source code on GitHub, but not required.

Badges

Made with Fresh

[![Made with Fresh](https://fresh.deno.dev/fresh-badge.svg)](https://fresh.deno.dev)
<a href="https://fresh.deno.dev">
   <img width="197" height="37" src="https://fresh.deno.dev/fresh-badge.svg" alt="Made with Fresh" />
</a>

Made with Fresh(dark)

[![Made with Fresh](https://fresh.deno.dev/fresh-badge-dark.svg)](https://fresh.deno.dev)
<a href="https://fresh.deno.dev">
   <img width="197" height="37" src="https://fresh.deno.dev/fresh-badge-dark.svg" alt="Made with Fresh" />
</a>
S
Description
No description provided
Readme MIT
44 MiB
Languages
TypeScript 96.7%
CSS 3.2%