All language subtitles for 005 Optimizing Data Fetching_Downloadly.ir_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian Download
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:02,110 --> 00:00:04,510 We implemented static generation 2 00:00:04,510 --> 00:00:08,420 on the index JS and the eventId JS pages. 3 00:00:08,420 --> 00:00:10,110 Now let's take a closer look. 4 00:00:10,110 --> 00:00:13,750 It works, but maybe we can optimize it. 5 00:00:13,750 --> 00:00:15,770 For example, on the starting page, 6 00:00:15,770 --> 00:00:17,760 so this index JS page. 7 00:00:17,760 --> 00:00:22,760 We are pre generating this page with the pre fetched data, 8 00:00:23,030 --> 00:00:23,905 so to say, 9 00:00:23,905 --> 00:00:27,850 but of course this data will then only update 10 00:00:27,850 --> 00:00:29,630 if we build again. 11 00:00:29,630 --> 00:00:32,850 So if our page was deployed for a couple of hours 12 00:00:32,850 --> 00:00:37,240 or even days, and we have new featured events, 13 00:00:37,240 --> 00:00:39,660 we need to redeploy our page 14 00:00:39,660 --> 00:00:42,570 to reflect that latest state. 15 00:00:42,570 --> 00:00:43,910 That's not ideal. 16 00:00:43,910 --> 00:00:46,990 And one possible work around could be to use, 17 00:00:46,990 --> 00:00:49,640 getStaticProps instead. 18 00:00:49,640 --> 00:00:52,080 Then for every incoming request, 19 00:00:52,080 --> 00:00:55,860 we would pre-render the page again on the fly 20 00:00:55,860 --> 00:00:58,060 but this would be overkill here. 21 00:00:58,060 --> 00:01:02,900 We don't need to pre generate this for every request, 22 00:01:02,900 --> 00:01:07,050 just a couple of times, maybe after a certain time span. 23 00:01:07,050 --> 00:01:11,770 And that's where we can add the revalidate key tutors object 24 00:01:11,770 --> 00:01:15,710 which we returned side-by-side to the props key. 25 00:01:15,710 --> 00:01:17,980 And we can set this to a value 26 00:01:17,980 --> 00:01:22,980 of our choice to 10 seconds, 100 seconds, 10 minutes 27 00:01:23,170 --> 00:01:25,210 whatever it makes sense to you. 28 00:01:25,210 --> 00:01:27,910 Now, our events and the featured events 29 00:01:27,910 --> 00:01:30,320 probably don't change that often. 30 00:01:30,320 --> 00:01:31,890 And it's not the end of the world 31 00:01:31,890 --> 00:01:33,740 if we did update them 32 00:01:33,740 --> 00:01:37,820 and our starting page, doesn't immediately reflect this. 33 00:01:37,820 --> 00:01:42,820 So maybe every 1,800 seconds is a good time span. 34 00:01:43,530 --> 00:01:48,440 That means that every half hour we regenerate this page 35 00:01:48,440 --> 00:01:51,100 for a new incoming request. 36 00:01:51,100 --> 00:01:54,110 And I think that would work quite well here. 37 00:01:54,110 --> 00:01:56,470 With that, this page still works, 38 00:01:56,470 --> 00:01:59,810 but in production, it would be regenerated 39 00:01:59,810 --> 00:02:00,970 from time to time, 40 00:02:00,970 --> 00:02:03,503 at most once every half hour. 41 00:02:05,080 --> 00:02:09,990 Now for eventId, we also could consider re-validating 42 00:02:09,990 --> 00:02:12,350 because there it's similar. 43 00:02:12,350 --> 00:02:15,048 If the details about any event changed, 44 00:02:15,048 --> 00:02:17,730 we don't reflect this on our page 45 00:02:17,730 --> 00:02:20,340 because we never regenerate it. 46 00:02:20,340 --> 00:02:24,060 Again, we could use service side rendering for that 47 00:02:24,060 --> 00:02:26,950 or we add clients site data fetching 48 00:02:26,950 --> 00:02:28,830 so that we have some initial data 49 00:02:28,830 --> 00:02:32,336 and we then update this with the client site data. 50 00:02:32,336 --> 00:02:37,336 But we could also go for re-validating instead here, 51 00:02:37,560 --> 00:02:42,550 and here I will also set revalidate to a certain interval. 52 00:02:42,550 --> 00:02:45,110 Now, I will not go for half an hour here, 53 00:02:45,110 --> 00:02:46,200 because for example, 54 00:02:46,200 --> 00:02:48,688 if the date changes, that's more important 55 00:02:48,688 --> 00:02:53,250 than the general list of featured events. 56 00:02:53,250 --> 00:02:56,500 It's still okay if it's slightly outdated 57 00:02:56,500 --> 00:02:58,240 but I wanna be more accurate 58 00:02:58,240 --> 00:03:00,110 than on the starting page. 59 00:03:00,110 --> 00:03:03,800 So, set this, let's say to 30 seconds, 60 00:03:03,800 --> 00:03:06,840 so that if a new request comes in and it's more 61 00:03:06,840 --> 00:03:10,620 than 30 seconds since the page was last generated, 62 00:03:10,620 --> 00:03:12,700 it will be generated again. 63 00:03:12,700 --> 00:03:15,150 I think that's a setting that makes sense here. 64 00:03:15,150 --> 00:03:17,650 Of course, you can also go for a different duration 65 00:03:17,650 --> 00:03:20,160 if that makes more sense to you though 66 00:03:20,160 --> 00:03:22,460 or alternatively you solved as 67 00:03:22,460 --> 00:03:24,550 with client site data fetching, 68 00:03:24,550 --> 00:03:28,120 in addition to the pre rendering here. 69 00:03:28,120 --> 00:03:30,910 Now, I also have an optimization idea 70 00:03:30,910 --> 00:03:33,360 regarding getStaticPaths. 71 00:03:33,360 --> 00:03:36,820 Currently, we're fetching all events here. 72 00:03:36,820 --> 00:03:37,830 Now, in our case, 73 00:03:37,830 --> 00:03:39,970 that's only free events, 74 00:03:39,970 --> 00:03:41,560 but on a real page, 75 00:03:41,560 --> 00:03:44,943 we could of course have hundreds or thousands of events. 76 00:03:45,780 --> 00:03:48,230 So fetching all those events, 77 00:03:48,230 --> 00:03:51,140 to pre generate all those pages 78 00:03:51,140 --> 00:03:54,180 could be a huge waste that might really 79 00:03:54,180 --> 00:03:57,793 be redundant and could lead to performance issues. 80 00:03:58,670 --> 00:04:00,160 So in reality, 81 00:04:00,160 --> 00:04:04,570 we might want to just pre-render our featured events 82 00:04:04,570 --> 00:04:07,390 because those are more likely to be visited 83 00:04:07,390 --> 00:04:09,763 because they're featured on the starting page. 84 00:04:10,640 --> 00:04:14,880 So therefore here, in eventId on this eventId page, 85 00:04:14,880 --> 00:04:18,300 instead of fetching all events and pre rendering 86 00:04:18,300 --> 00:04:22,180 all the pages, all the detail pages for all events, 87 00:04:22,180 --> 00:04:25,960 I will instead just load my featured events 88 00:04:25,960 --> 00:04:28,320 and therefore import getFeaturedEvents 89 00:04:28,320 --> 00:04:30,853 from the API util helper file, 90 00:04:32,720 --> 00:04:37,720 and then just simply execute getFeaturedEvents down there. 91 00:04:39,170 --> 00:04:42,230 But now with that, of course, that implies 92 00:04:42,230 --> 00:04:47,230 that for some events, the page will not be pre-generated. 93 00:04:47,260 --> 00:04:52,260 So if we leave fallback set to false, we'll have an issue. 94 00:04:52,640 --> 00:04:56,620 If I click on some event, which was not, pre-generated 95 00:04:56,620 --> 00:04:59,830 like this event with an idea of E1, 96 00:04:59,830 --> 00:05:02,290 I get a 404 error 97 00:05:02,290 --> 00:05:05,700 even though we have data for this event 98 00:05:05,700 --> 00:05:07,140 but we didn't define it 99 00:05:07,140 --> 00:05:10,100 in advance and therefore it wasn't pre-generated. 100 00:05:10,100 --> 00:05:14,130 And since we tell next.js that we did prepare 101 00:05:14,130 --> 00:05:15,653 all required pages here, 102 00:05:15,653 --> 00:05:20,360 that's what we tell next.js with fallback false. 103 00:05:20,360 --> 00:05:23,470 It shows as a 404 page here. 104 00:05:23,470 --> 00:05:25,170 So the correct setting here, 105 00:05:25,170 --> 00:05:27,070 would be true, 106 00:05:27,070 --> 00:05:30,280 telling next.js that there are more pages 107 00:05:30,280 --> 00:05:32,223 than the ones we prepared here. 108 00:05:33,170 --> 00:05:36,330 Then it will try to dynamically generate the page 109 00:05:36,330 --> 00:05:41,000 if it encounters a page which was not pre-generated before. 110 00:05:41,000 --> 00:05:44,540 Now, if we do that, it works. 111 00:05:44,540 --> 00:05:46,850 Now we see no event found initially 112 00:05:46,850 --> 00:05:48,811 until the event was fetched 113 00:05:48,811 --> 00:05:52,790 because we are checking if we don't have any event. 114 00:05:52,790 --> 00:05:56,410 And then we showed us fallback and that's good. 115 00:05:56,410 --> 00:05:59,560 We should show a fallback content 116 00:05:59,560 --> 00:06:03,140 whilst we are waiting for the event to arrive 117 00:06:03,140 --> 00:06:06,010 but here it might be better to show some 118 00:06:06,010 --> 00:06:07,080 a loading spinner 119 00:06:07,080 --> 00:06:10,450 or some loading text instead of an error. 120 00:06:10,450 --> 00:06:13,810 Because here it's now actually expected for some events 121 00:06:13,810 --> 00:06:15,910 which haven't been pre-generated 122 00:06:15,910 --> 00:06:18,840 that we don't have them right from the start. 123 00:06:18,840 --> 00:06:21,890 So instead of wrapping this into an error alert, 124 00:06:21,890 --> 00:06:24,630 I'll wrap this in a regular div instead 125 00:06:24,630 --> 00:06:29,360 and give that div a class name of center 126 00:06:29,360 --> 00:06:32,220 which is a globally available class name 127 00:06:32,220 --> 00:06:34,793 to find in the global CSS file. 128 00:06:36,370 --> 00:06:41,370 And then I'll then say loading instead of no event found. 129 00:06:41,800 --> 00:06:43,783 And therefore, now if we reload, 130 00:06:43,783 --> 00:06:47,130 we see loading until the event is there 131 00:06:47,130 --> 00:06:48,800 so that's better. 132 00:06:48,800 --> 00:06:50,340 Alternatively, of course, 133 00:06:50,340 --> 00:06:55,030 we set fallback, not too true, but to blocking. 134 00:06:55,030 --> 00:06:58,880 In that case, next.js will not serve anything 135 00:06:58,880 --> 00:07:01,940 until we're done generating this page. 136 00:07:01,940 --> 00:07:03,890 So if I do that and reload, 137 00:07:03,890 --> 00:07:06,540 then loading the page takes a bit longer 138 00:07:06,540 --> 00:07:09,270 but we get the entire finished page 139 00:07:09,270 --> 00:07:11,230 right from the start. 140 00:07:11,230 --> 00:07:15,300 It's up to you which user experience you want on your page 141 00:07:15,300 --> 00:07:17,920 or stick to this blocking approach 142 00:07:17,920 --> 00:07:21,200 but you can go for either of the two. 143 00:07:21,200 --> 00:07:24,810 And these were a couple of small optimized session steps 144 00:07:24,810 --> 00:07:27,320 which I did want to implement. 145 00:07:27,320 --> 00:07:28,590 Now with that, let's go back 146 00:07:28,590 --> 00:07:30,930 to the two remaining pages we have, 147 00:07:30,930 --> 00:07:34,400 maybe first to the index.js page and the events folder 148 00:07:34,400 --> 00:07:38,070 and let's make sure we also pre-render those correctly 149 00:07:38,070 --> 00:07:41,210 with data which is fetched in advance. 150 00:07:41,210 --> 00:07:43,150 Try implementing it on your own. 151 00:07:43,150 --> 00:07:45,733 We'll do it together in the next lecture. 11713

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.