Skip to content

Commit 96941e3

Browse files
author
Jason Barry
committed
Adding more content to readme
1 parent b290c7a commit 96941e3

File tree

4 files changed

+52
-7
lines changed

4 files changed

+52
-7
lines changed

README.md

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,60 @@ i. Edge Functions are also great places to add A/B testing. You can add a cookie
217217

218218
<details><summary>Part 5: Globally persist data with Blobs</summary>
219219

220-
Here, we'll discuss how to read and write data to blob storage.
220+
**🧑‍💻 Relevant demo and code:**
221+
222+
- [Access blob storage](https://netlify-core-workshop.netlify.app/primitives/functions/blobs) ([netlify/functions/blob.ts](https://github.com/netlify/netlify-workshop/blob/main/netlify/functions/blob.ts))
223+
224+
Netlify Blobs is a highly-available S3-like data store optimized for frequent reads and infrequent writes. Provisioning, configuration, and access control is handled automatically. This integrated zero-configuration solution helps you focus on building business value in your project rather than toil on setting up and scaling a separate blob storage solution.
225+
226+
With Blobs, you can store and retrieve unstructured data extremely easily. Blobs are ubiquitous: you can access them in the build, in functions, and in edge functions.
227+
228+
```ts
229+
import { getStore } from "@netlify/blobs";
230+
231+
export default async (req: Request) => {
232+
const store = getStore("ntl-workshop-todos");
233+
234+
if (req.method === "GET") {
235+
const todos = await store.get("todos", { type: "json" });
236+
return new Response(todos || JSON.stringify([]), { status: 200 });
237+
}
238+
239+
if (req.method === "PUT") {
240+
const body = await req.json();
241+
await store.setJSON("todos", body);
242+
return new Response("Todos updated", { status: 200 });
243+
}
244+
};
245+
```
246+
247+
💡 Learn more about [Netlify Blobs](https://docs.netlify.com/blobs/overview/) in our docs.
221248

222249
</details>
223250

224251
<details><summary>Part 6: Optimize images at runtime with Image CDN</summary>
225252

226-
Here, we'll discuss how easy it is to optimize images at runtime with Image CDN.
253+
**🧑‍💻 Relevant demo and code:**
254+
255+
- [Same-origin images](https://netlify-core-workshop.netlify.app/primitives/image-cdn/same-origin) ([src/pages/primitives/image-cdn/same-origin.tsx](https://github.com/netlify/netlify-workshop/blob/main/src/pages/primitives/image-cdn/same-origin.tsx))
256+
- [Remote images](https://netlify-core-workshop.netlify.app/primitives/image-cdn/remote) ([src/pages/primitives/image-cdn/remote.tsx](https://github.com/netlify/netlify-workshop/blob/main/src/pages/primitives/image-cdn/remote.tsx))
257+
258+
You may have experienced pain points in the past dealing with image optimizations for the web. Do you keep raw source images in a repo, and run them through `sharp` or `image-magick` at during the build? That would increase build time and costs significantly. Either way, you'd still need to deal with various image formats, sizing, pixel density, `srcset` attributes, etc.
259+
260+
With Netlify Image CDN, you can transform images on demand without impacting build times. Image CDN also handles content negotiation to use the most efficient image format for the requesting client. Optimizing the size and format of your images improves both the runtime performance and reliability of your site. Transformations are integrated natively into the CDN so that repeated requests leverage layers of caching for improved performance.
261+
262+
To use Netlify Image CDN, simply prefix your image URLs with `/.netlify/images?url=`:
263+
264+
```diff
265+
- <img src="/owl.jpeg" />
266+
+ <img src="/.netlify/images?url=/owl.jpeg" />
267+
```
268+
269+
The next time you request that image, you'll see the format be converted on-the-fly to a more optimal compression format that your browser supports. There's no need to pre-generate images of different formats, or stuff multiple URLs in a `srcset` attribute -- it's all handled at request-time, and cached on Netlify's CDN.
270+
271+
You can configure many other aspects of the image, such as size, fit, position, format, and quality, by passing in [additional query parameters](https://docs.netlify.com/image-cdn/overview/#transform-images).
272+
273+
💡 Learn more about [Image CDN](https://docs.netlify.com/image-cdn/overview/) in our docs.
227274

228275
</details>
229276

netlify/functions/blob.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ export default async (req: Request) => {
44
const store = getStore("ntl-workshop-todos");
55

66
if (req.method === "GET") {
7-
const todos = await store.get("todos");
7+
const todos = await store.get("todos", { type: "json" });
88
return new Response(todos || JSON.stringify([]), { status: 200 });
99
}
1010

1111
if (req.method === "PUT") {
1212
const body = await req.json();
13-
await store.set("todos", JSON.stringify(body));
13+
await store.setJSON("todos", body);
1414
return new Response("Todos updated", { status: 200 });
1515
}
1616

src/pages/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ export default function Index() {
7474
<h3>Blobs</h3>
7575
<ul>
7676
<li>
77-
<Link href="/primitives/functions/blobs">
78-
Access blob storage
79-
</Link>
77+
<Link href="/primitives/blobs/blobs">Access blob storage</Link>
8078
</li>
8179
</ul>
8280
<h3>Image CDN</h3>

0 commit comments

Comments
 (0)