项目作者: DmitryMyadzelets

项目描述 :
Example of the server-side and client-side rendering in Svelte
高级语言: JavaScript
项目地址: git://github.com/DmitryMyadzelets/svelte-server-client-rendering.git
创建时间: 2021-01-16T15:20:07Z
项目社区:https://github.com/DmitryMyadzelets/svelte-server-client-rendering

开源协议:MIT License

下载


svelte-server-client-rendering

Example of the server-side, client-side and static rendering with
Svelte. For self-learning.

  1. npm install
  2. npm run build
  3. npm start

How it works

When you execute npm run build you compile and render static files. Here
we use the Rollup bundler. It’s controlled by the
rollup.config.js file. We have two configurations there: the first compiles
Client.svelte and creates the public/client.js file, the second compiles
Static.svelte and outputs the rendering results to the static.html file.

With npm start command you start a primitive server written in the index.js file.
The server-side rendering occurs when the server is preparing a response to a client.
For the root / URL the server creates html rendered by the Server.svelte. During rendering it uses the static.html which was rendered as a static content.
For any other URL our server assumes that static files are requested from the public directory.

The client-side rendering happens when a browser loads and executes the client.js file.

In the browser you’ll see results of the every rendering. It will help you with
understanding where and when it was done.