Fireship · @fireship

SvelteKit in 100 seconds

Uploaded July 19, 2023 · Length 2:46

SvelteKit in 100 seconds

Summary

SvelteKit framework for server-rendered web apps with UI Library, universal rendering, and built-in router.

  • sveltekit
  • server-rendered
  • universal rendering
  • ui library
  • javascript framework

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    spelled kit a framework for building

  2. 0:02

    server-rendered web applications with

  3. 0:03

    the world's most loved UI Library it was

  4. 0:06

    created by the creator of spelled

  5. 0:07

    himself Rich Harris and hit version 1.0

  6. 0:09

    in 2022 most importantly it provides a

  7. 0:12

    universal way to render svelte on

  8. 0:13

    node.js and other JavaScript Edge

  9. 0:15

    runtimes this allows the server to fetch

  10. 0:18

    data up front so the browser can receive

  11. 0:19

    fully rendered HTML which can be

  12. 0:21

    critical for performance and SEO then

  13. 0:23

    JavaScript takes over to render all

  14. 0:25

    future Pages like a fast and smooth

  15. 0:27

    single page application it provides a

  16. 0:29

    built-in router where every page

  17. 0:31

    component represents the UI for a unique

  18. 0:33

    URL each component though can have a

  19. 0:35

    corresponding Javascript file to handle

  20. 0:37

    data fetching this file exports a load

  21. 0:39

    function and the return value is made

  22. 0:40

    available on the component while

  23. 0:42

    providing automatic end-to-end type

  24. 0:43

    safety in addition the data is made

  25. 0:45

    available on a svelt store which can be

  26. 0:47

    accessed from any component and

  27. 0:48

    eliminates the need for complex State

  28. 0:50

    Management architectures Pages can also

  29. 0:52

    handle server-side actions like form

  30. 0:54

    submissions to update the current page

  31. 0:56

    with zero client-side JavaScript forms

  32. 0:58

    can then be progressively enhanced to

  33. 0:59

    improve of the front end user experience

  34. 1:01

    with JavaScript in addition to Pages

  35. 1:03

    layouts can be used to share UI across

  36. 1:05

    multiple child routes and they can even

  37. 1:07

    fetch their own data and finally we have

  38. 1:09

    server files that export functions like

  39. 1:11

    git post patch and delete to build

  40. 1:13

    restful apis to get started create a new

  41. 1:16

    project with a CLI you'll notice it uses

  42. 1:18

    Veet as the build tool then we can

  43. 1:19

    create our first page by going to the

  44. 1:21

    routes directory right click and the

  45. 1:23

    tooling will help you easily create the

  46. 1:24

    required file I'm wrapping this URL in

  47. 1:26

    Brackets to make it a dynamic route that

  48. 1:28

    will give us a username parameter we can

  49. 1:30

    access throughout the application notice

  50. 1:32

    how the component has a prop of data

  51. 1:34

    using the page data interface this

  52. 1:36

    interface is automatically generated

  53. 1:37

    based on how we load data from the

  54. 1:39

    server in the application that data can

  55. 1:41

    be loaded from a page.ts file inside the

  56. 1:43

    load function we can access the URL

  57. 1:45

    parameters like we might take the

  58. 1:47

    username and make a fetch call to an API

  59. 1:49

    once we have our data we just return it

  60. 1:51

    from this function then we can access it

  61. 1:52

    with full intellisense back in the UI

  62. 1:54

    component the initial page load will be

  63. 1:56

    rendered on the server and we can use

  64. 1:57

    felt head to set a title in meta tags

  65. 1:59

    for search Bots we might also want to