Lattice Flashcards

1
Q

CSR

A

Client-Side Rendering

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

SSR

A

Server-Side Rendering

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

SSG

A

Static-Site Generation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is Next js?

A

Next.js is a React framework that gives you building blocks like routing, data fetching, to create web applications

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the difference between props and state?

A

Props is read-only information that’s passed to components. State is information that can change over time, usually triggered by user interaction

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the difference between compiling and bundling in web development?

A

Compiling is transforming code into something parsable by browsers. Bundling is resolving your applications dependency graph and reducing the number of files

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is code-splitting?

A

the process of splitting the application’s bundle into smaller chunks required by each entry point. The goal is to improve the application’s initial load time by only loading the code required to run that page.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

React server components

A

Server components are completely rendered on the server and do not require client-side JavaScript to render. In addition, server components allow developers to keep some logic on the server and only send the result of that logic to the client. This reduces the bundle size sent to the client and improves client-side rendering performance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

SSR

A

the HTML of the page is generated on a server for each request. The generated HTML, JSON data, and JavaScript instructions to make the page interactive are then sent to the client. Which then makes the content interactive in a process called hydration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

SSG

A

the HTML is generated on the server, but unlike server-side rendering, there is no server at runtime. Instead, content is generated once, at build time, when the application is deployed, and the HTML is stored in a CDN and re-used for each request.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What do CDN’s do?

A

store static content (such as HTML and image files) in multiple locations around the world and are placed between the client and the origin server. When a new request comes in, the closest CDN location to the user can respond with the cached result.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do CDN’s increase performance?

A

they reduce the load on the origin because the computation doesn’t have to happen on each request. It also makes it faster for the user because the response comes from a location geographically closer to them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The Edge

A

Edge servers are distributed to multiple locations around the world. But unlike CDNs, which store static content, some Edge servers can run code.

This means both caching and code execution can be done at the Edge closer to the user.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does next js give us?

A
  • page-based routing system
  • page-based pre-rendering (SSR and SSG)
  • code splitting
  • sass, CSS in js support
  • fast refresh
  • API routes
  • pre-fetching
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

how do you do client-side navigation with next js?

A

<a>homepage</a>

import Link from ‘next/link’;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

how does prefetching with Next js work?

A

whenever Link components appear in the browser’s viewport, Next.js automatically prefetches the code for the linked page in the background. (in production)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

how do you create routes in next js?

A

by adding files under the ‘pages’ directory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What benefits does the Next js Image component have?

A
  • Ensuring your image is responsive on different screen sizes
  • Optimizing your images with a third-party tool or library
  • Only loading images when they enter the viewport
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What benefits does the Next js Script component have?

A

optimizes when scripts are fetched and executed

- strategy controls when the third-party script should load

20
Q

what styling methods does Next js have built-in support for?

A

CSS Modules, Sass, styled-jsx

21
Q

where are global styles added in Next js?

A

in pages/_app.js only, they can not be imported in other files

22
Q

what is kept in pages/_app.js?

A

is the top-level component which will be common across all the different pages. You can use this App component to keep state when navigating between pages, for example.

23
Q

What question can you ask to determine if you should use SSG?

A

Can I pre-render this page ahead of a user’s request?

24
Q

When should you not use SSG?

A

if you cannot pre-render a page ahead of a user’s request. Maybe your page shows frequently updated data, and the page content changes on every request.

25
Q

When would you use Server-side rendering?

A

When the data needs to be up-to-date with every request

26
Q

how do you use SSG with Data?

A

when you export a page component, you can also export an async function called getStaticProps

  • getStaticProps runs at build time in production, and…
  • Inside the function, you can fetch external data and send it as props to the page.
27
Q

Where does getStaticProps run and work?

A

only runs on the server-side. It will never run on the client-side. It won’t even be included in the JS bundle for the browser. That means you can write code such as direct database queries

28
Q

What is a side effect of getStaticProps only being run at build time?

A

you won’t be able to use data that’s only available during request time, such as query parameters or HTTP headers

29
Q

Where can you use getStaticProps?

A

only in a page

30
Q

how do you use SSR with Data?

A

you need to export getServerSideProps from a page

Because getServerSideProps is called at request time, its parameter (context) contains request-specific parameters.

31
Q

When should you use SSR? Why?

A

only if you need to pre-render a page whose data must be fetched at request time. Time to first byte (TTFB) will be slower than getStaticProps because the server must compute the result on every request, and the result cannot be cached by a CDN without extra configuration.

32
Q

Client-side Rendering

A
Statically generate (pre-render) parts of the page that do not require external data.
When the page loads, fetch external data from the client using JavaScript and populate the remaining parts.
33
Q

When is CSR useful?

A

for user dashboard pages, for example. Because a dashboard is a private, user-specific page, SEO is not relevant, and the page doesn’t need to be pre-rendered. The data is frequently updated, which requires request-time data fetching.

34
Q

how do we create a dynamic route in Next js?

A

in the pages directory files that begin with [ and end in ] are dynamic. [id].js
1. Create the file and component
2 export a getStaticPaths function which returns an array of possible values for the [..]
3. export a getStaticPros which fetches necessary data for the dynamic content

35
Q

How does params.id from getStaticProps({ params }) know the key is named id?

A

The value from the file name

36
Q

How does params.id from getStaticProps({ params }) know the key is named id?

A

The value from the file name

37
Q

what happens if we return fallback: false from getStaticPaths?

A

then any paths not returned by getStaticPaths will result in a 404 page.

38
Q

what happens if we return fallback: true from getStaticPaths?

A
  1. The paths returned from getStaticPaths will be rendered to HTML at build time.
  2. The paths that have not been generated at build time will not result in a 404 page. Instead, Next.js will serve a “fallback” version of the page on the first request to such a path.
  3. In the background, Next.js will statically generate the requested path. Subsequent requests to the same path will serve the generated page, just like other pages pre-rendered at build time.
39
Q

what happens if we return fallback: ‘blocking’ from getStaticPaths?

A

then new paths will be server-side rendered with getStaticProps, and cached for future requests so it only happens once per path

40
Q

how do you create a catch-all route?

A

by adding three dots inside the brackets

pages/posts/[...id].js matches /posts/a, but also /posts/a/b, /posts/a/b/c

41
Q

how do you need to change getStaticPaths when creating a catch-all route?

A

you must return an array as the value of the id key like so:

return [
  {
    params: {
      // Statically Generates /posts/a/b/c
      id: ['a', 'b', 'c'],
    },
  },
  //...
];
export async function getStaticProps({ params }) {
  // params.id will be like ['a', 'b', 'c']
}
42
Q

how can you create a 404 page?

A

create a pages/404.js file

43
Q

What are some good use case for an API Route?

A

Saving incoming data to your database
Securely communicating with a third-party API
Previewing draft content from your CMS

44
Q

in what was are API routes secure?

A

API Route code will not be part of your client bundle, so you can safely write server-side code

45
Q

event.target

A

whatever element somebody actually clicked on. It can vary, as this can be within an element that the event was bound to.

46
Q

event.currentTarget

A

is the element you actually bound the event to. This will never change.