
Learner and teacher #javascript #postgres #node #express 😃😃😉
- Tweets179
- Following162
- Followers34
- Likes114
![Astro tips SVELTE WITH ASTRO: STARTING OUT Astro lets you build fast static sites - You can mix **Svelte**, React or Vue components, - **islands architecture** lets you optimise page load making your site fast, - **partial hydration** lets you ship **less JavaScript** keeping your app lean. To get going with **Svelte** in Astro: - install `@astrojs/renderer-svelte`, then - add the renderer to the `astro.config.mjs` file: // Terminal mkdir my-new-astro-project && cd $_ pnpm init astro pnpm install pnpm add -D @astrojs/renderer-svelte vite pnpm run dev // astro.config.mjs export default ({ renderers: ['@astrojs/renderer-svelte'], });](https://pbs.twimg.com/media/FKbl5U4XoAcr-Im.jpg?name=small&format=webp)
ALT Astro tips SVELTE WITH ASTRO: STARTING OUT Astro lets you build fast static sites - You can mix **Svelte**, React or Vue components, - **islands architecture** lets you optimise page load making your site fast, - **partial hydration** lets you ship **less JavaScript** keeping your app lean. To get going with **Svelte** in Astro: - install `@astrojs/renderer-svelte`, then - add the renderer to the `astro.config.mjs` file: // Terminal mkdir my-new-astro-project && cd $_ pnpm init astro pnpm install pnpm add -D @astrojs/renderer-svelte vite pnpm run dev // astro.config.mjs export default ({ renderers: ['@astrojs/renderer-svelte'], });
![Svelte tips UPDATE: SVELTEKIT ENDPOINTS // src/routes/[slug].svelte const response = await fetch(`/${slug}.json`, { method: 'POST', credentials: 'include', body: JSON.stringify({ name: 'Blake', }), }); SvelteKit endpoints let you pass data into your page components - You can create **endpoints** which **respond** to the usual HTTP verbs (`GET`, `POST` etc.), - it can be convenient to pass in and respond with **JSON** data. Create a `[slug].json.ts` file to listen on `/example-slug.json` with a `post` function for `POST` requests: - `params` lets you access route params, like `slug`, - `request` lets you access **headers** and the **JSON** body: // src/routes/[slug].json.ts import type { EndpointOutput, RequestEvent } from "@sveltejs/kit"; export async function post({ params, request, }: RequestEvent & { params: { slug: string } }): Promise<EndpointOutput> { try { const { name } = await request.json(); const myHeaderValue = request.headers.get("My-Header");](https://pbs.twimg.com/media/FKBo2xgX0AMUd8s.jpg?name=small&format=webp)
ALT Svelte tips UPDATE: SVELTEKIT ENDPOINTS // src/routes/[slug].svelte const response = await fetch(`/${slug}.json`, { method: 'POST', credentials: 'include', body: JSON.stringify({ name: 'Blake', }), }); SvelteKit endpoints let you pass data into your page components - You can create **endpoints** which **respond** to the usual HTTP verbs (`GET`, `POST` etc.), - it can be convenient to pass in and respond with **JSON** data. Create a `[slug].json.ts` file to listen on `/example-slug.json` with a `post` function for `POST` requests: - `params` lets you access route params, like `slug`, - `request` lets you access **headers** and the **JSON** body: // src/routes/[slug].json.ts import type { EndpointOutput, RequestEvent } from "@sveltejs/kit"; export async function post({ params, request, }: RequestEvent & { params: { slug: string } }): Promise<EndpointOutput> { try { const { name } = await request.json(); const myHeaderValue = request.headers.get("My-Header");
![Svelte tips UPDATE: SVELTEKIT ENDPOINTS // src/routes/[slug].svelte const response = await fetch(`/${slug}.json`, { method: 'POST', credentials: 'include', body: JSON.stringify({ name: 'Blake', }), }); SvelteKit endpoints let you pass data into your page components - You can create **endpoints** which **respond** to the usual HTTP verbs (`GET`, `POST` etc.), - it can be convenient to pass in and respond with **JSON** data. Create a `[slug].json.js` file to listen on `/example-slug.json` with a `post` function for `POST` requests: - `params` lets you access route params, like `slug`, - `request` lets you access **headers** and the **JSON** body: // src/routes/[slug].json.js export async function post({ params, request}}) { try { const { name } = await request.json(); const myHeaderValue = request.headers.get("My-Header"); const { slug } = params; // ...TRUNCATED](https://pbs.twimg.com/media/FKCzNt4XMAYd14e.jpg?name=small&format=webp)
ALT Svelte tips UPDATE: SVELTEKIT ENDPOINTS // src/routes/[slug].svelte const response = await fetch(`/${slug}.json`, { method: 'POST', credentials: 'include', body: JSON.stringify({ name: 'Blake', }), }); SvelteKit endpoints let you pass data into your page components - You can create **endpoints** which **respond** to the usual HTTP verbs (`GET`, `POST` etc.), - it can be convenient to pass in and respond with **JSON** data. Create a `[slug].json.js` file to listen on `/example-slug.json` with a `post` function for `POST` requests: - `params` lets you access route params, like `slug`, - `request` lets you access **headers** and the **JSON** body: // src/routes/[slug].json.js export async function post({ params, request}}) { try { const { name } = await request.json(); const myHeaderValue = request.headers.get("My-Header"); const { slug } = params; // ...TRUNCATED
![Svelte tips UPDATE: SVELTEKIT CSR ROUTES // src/routes/london-office-map.svelte // STATIC PAGE <script context="module"> export const prerender = true; </script> SvelteKit can render pages statically or with Server Side Rendering - You can make **all** pages **static** using `@sveltejs/adapter-static`, - or choose on a **page-by-page** basis which pages to make static adding `prerender=true` (as above). On top you can opt routes into an SPA style **Client Side Render**. For this: - create a `src/hooks.js` file, - filter routes and set `ssr: false` for CSR pages: // src/hooks.js - CLIENT SIDE RENDERED PAGE export async function handle({ event, resolve }) const { pathname } = event?.url ?? {}; const regex = /^\/[-\w]+-map$/; if (pathname && regex.test(pathname)) { return resolve(event, { ssr: false, }); } return resolve(event); }](https://pbs.twimg.com/media/FJ90XS_WUAMOLDZ.jpg?name=small&format=webp)
ALT Svelte tips UPDATE: SVELTEKIT CSR ROUTES // src/routes/london-office-map.svelte // STATIC PAGE <script context="module"> export const prerender = true; </script> SvelteKit can render pages statically or with Server Side Rendering - You can make **all** pages **static** using `@sveltejs/adapter-static`, - or choose on a **page-by-page** basis which pages to make static adding `prerender=true` (as above). On top you can opt routes into an SPA style **Client Side Render**. For this: - create a `src/hooks.js` file, - filter routes and set `ssr: false` for CSR pages: // src/hooks.js - CLIENT SIDE RENDERED PAGE export async function handle({ event, resolve }) const { pathname } = event?.url ?? {}; const regex = /^\/[-\w]+-map$/; if (pathname && regex.test(pathname)) { return resolve(event, { ssr: false, }); } return resolve(event); }










