generated from taylorbryant/gatsby-starter-tailwind
-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve landing page load time (#1124)
* refactor: optimizing landing page. set revalidate at `fetch` call * refactor: use experimental apollo client for server component
- Loading branch information
Showing
16 changed files
with
152 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client' | ||
import { registerApolloClient } from '@apollo/experimental-nextjs-app-support/rsc' | ||
|
||
const uri: string = process.env.NEXT_PUBLIC_API_SERVER ?? '' | ||
|
||
if (uri === '' || uri == null) { | ||
throw new Error('NEXT_PUBLIC_API_SERVER is not set') | ||
} | ||
|
||
/** | ||
* Apollo client to be used in server components. | ||
*/ | ||
export const { getClient } = registerApolloClient(() => { | ||
return new ApolloClient({ | ||
cache: new InMemoryCache(), | ||
link: new HttpLink({ | ||
uri, | ||
fetchOptions: { | ||
next: { revalidate: 3600 } // a non-zero value enables 'public, max-age=0, must-revalidate' | ||
} | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { getClient } from '../ServerClient' | ||
import { MediaByUsers } from '@/js/types' | ||
import { QUERY_MEDIA_FOR_FEED } from './tags' | ||
|
||
/** | ||
* Server component API: Get recent media for feed. | ||
* @param maxUsers | ||
* @param maxFiles | ||
*/ | ||
export const getMediaForFeedSC = async (maxUsers: number, maxFiles: number): Promise<MediaByUsers[]> => { | ||
try { | ||
const rs = await getClient().query<{ getMediaForFeed: MediaByUsers[] }>({ | ||
query: QUERY_MEDIA_FOR_FEED, | ||
variables: { | ||
maxUsers, | ||
maxFiles | ||
}, | ||
fetchPolicy: 'cache-first' | ||
}) | ||
|
||
if (Array.isArray(rs.data?.getMediaForFeed)) { | ||
return rs.data?.getMediaForFeed | ||
} | ||
console.log('WARNING: getMediaForFeed() returns non-array data') | ||
return [] | ||
} catch (e) { | ||
console.log('####### getMediaForFeed() error', e) | ||
} | ||
return [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,25 +60,41 @@ | |
"@jridgewell/gen-mapping" "^0.3.0" | ||
"@jridgewell/trace-mapping" "^0.3.9" | ||
|
||
"@apollo/client@^3.7.16": | ||
version "3.8.4" | ||
resolved "https://registry.npmjs.org/@apollo/client/-/client-3.8.4.tgz" | ||
integrity sha512-QFXE4ylSHUa6LgYoOGsPysJCm4YJOOM1NwHyF6msZdZXIerqUVpLvxQOdQEXgS0RWvYiBMC1wGOWKzJKSWBdAg== | ||
"@apollo/[email protected]": | ||
version "0.10.0" | ||
resolved "https://registry.yarnpkg.com/@apollo/client-react-streaming/-/client-react-streaming-0.10.0.tgz#1f9a818c679b41791ca02105f16525c93412994c" | ||
integrity sha512-iZ2jYghRS71xFv6O3Js5Ojrrmk4SnIEKwPRKIswQyAtqjHrfvUTyXCDzxrhPcGQe/y7su/XcE7Xp0kOp7yTnlg== | ||
dependencies: | ||
superjson "^1.12.2 || ^2.0.0" | ||
ts-invariant "^0.10.3" | ||
|
||
"@apollo/client@^3.10.1": | ||
version "3.10.1" | ||
resolved "https://registry.yarnpkg.com/@apollo/client/-/client-3.10.1.tgz#4c8eec28fcce25b96f27c1f1e443ec5c676e4de0" | ||
integrity sha512-QNacQBZzJla5UQ/LLBXJWM7/1v1C5cfpMQPAFjW4hg4T54wHWbg4Dr+Dp6N+hy/ygu8tepdM+/y/5VFLZhovlQ== | ||
dependencies: | ||
"@graphql-typed-document-node/core" "^3.1.1" | ||
"@wry/context" "^0.7.3" | ||
"@wry/caches" "^1.0.0" | ||
"@wry/equality" "^0.5.6" | ||
"@wry/trie" "^0.4.3" | ||
"@wry/trie" "^0.5.0" | ||
graphql-tag "^2.12.6" | ||
hoist-non-react-statics "^3.3.2" | ||
optimism "^0.17.5" | ||
optimism "^0.18.0" | ||
prop-types "^15.7.2" | ||
rehackt "^0.1.0" | ||
response-iterator "^0.2.6" | ||
symbol-observable "^4.0.0" | ||
ts-invariant "^0.10.3" | ||
tslib "^2.3.0" | ||
zen-observable-ts "^1.2.5" | ||
|
||
"@apollo/experimental-nextjs-app-support@^0.10.0": | ||
version "0.10.0" | ||
resolved "https://registry.yarnpkg.com/@apollo/experimental-nextjs-app-support/-/experimental-nextjs-app-support-0.10.0.tgz#2fe52e6bc18de87c17bfc2bc78ec63acf8260c8f" | ||
integrity sha512-S3mfZRnAAAaKwA8RNckS4TWYLX5utpmRTwG3WGFtpooYx8QQG8xft0p0a9eTQ53Jrw3nSMJc/wOOsT/5noMCQg== | ||
dependencies: | ||
"@apollo/client-react-streaming" "0.10.0" | ||
|
||
"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.22.13": | ||
version "7.22.13" | ||
resolved "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.13.tgz" | ||
|
@@ -3017,7 +3033,14 @@ | |
resolved "https://registry.yarnpkg.com/@vercel/edge/-/edge-1.1.1.tgz#9b2fc0081dfe95db8b4c3598275721b1ad85e43f" | ||
integrity sha512-NtKiIbn9Cq6HWGy+qRudz28mz5nxfOJWls5Pnckjw1yCfSX8rhXdvY/il3Sy3Zd5n/sKCM2h7VSCCpJF/oaDrQ== | ||
|
||
"@wry/context@^0.7.0", "@wry/context@^0.7.3": | ||
"@wry/caches@^1.0.0": | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/@wry/caches/-/caches-1.0.1.tgz#8641fd3b6e09230b86ce8b93558d44cf1ece7e52" | ||
integrity sha512-bXuaUNLVVkD20wcGBWRyo7j9N3TxePEWFZj2Y+r9OoUzfqmavM84+mFykRicNsBqatba5JLay1t48wxaXaWnlA== | ||
dependencies: | ||
tslib "^2.3.0" | ||
|
||
"@wry/context@^0.7.0": | ||
version "0.7.3" | ||
resolved "https://registry.npmjs.org/@wry/context/-/context-0.7.3.tgz" | ||
integrity sha512-Nl8WTesHp89RF803Se9X3IiHjdmLBrIvPMaJkl+rKVJAYyPsz1TEUbu89943HpvujtSJgDUx9W4vZw3K1Mr3sA== | ||
|
@@ -3038,6 +3061,13 @@ | |
dependencies: | ||
tslib "^2.3.0" | ||
|
||
"@wry/trie@^0.5.0": | ||
version "0.5.0" | ||
resolved "https://registry.yarnpkg.com/@wry/trie/-/trie-0.5.0.tgz#11e783f3a53f6e4cd1d42d2d1323f5bc3fa99c94" | ||
integrity sha512-FNoYzHawTMk/6KMQoEG5O4PuioX19UbwdQKF44yw0nLfOypfQdjtfZzo/UIJWAJ23sNIFbD1Ug9lbaDGMwbqQA== | ||
dependencies: | ||
tslib "^2.3.0" | ||
|
||
"@xobotyi/scrollbar-width@^1.9.5": | ||
version "1.9.5" | ||
resolved "https://registry.npmjs.org/@xobotyi/scrollbar-width/-/scrollbar-width-1.9.5.tgz" | ||
|
@@ -3849,6 +3879,13 @@ cookiejar@^2.1.3: | |
resolved "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.4.tgz" | ||
integrity sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw== | ||
|
||
copy-anything@^3.0.2: | ||
version "3.0.5" | ||
resolved "https://registry.yarnpkg.com/copy-anything/-/copy-anything-3.0.5.tgz#2d92dce8c498f790fa7ad16b01a1ae5a45b020a0" | ||
integrity sha512-yCEafptTtb4bk7GLEQoM8KVJpxAfdBJYaXyzQEgQQQgYrZiDp8SJmGKlYza6CYjEDNstAdNdKA3UuoULlEbS6w== | ||
dependencies: | ||
is-what "^4.1.8" | ||
|
||
copy-to-clipboard@^3.3.1: | ||
version "3.3.3" | ||
resolved "https://registry.npmjs.org/copy-to-clipboard/-/copy-to-clipboard-3.3.3.tgz" | ||
|
@@ -5847,6 +5884,11 @@ is-weakset@^2.0.1: | |
call-bind "^1.0.2" | ||
get-intrinsic "^1.1.1" | ||
|
||
is-what@^4.1.8: | ||
version "4.1.16" | ||
resolved "https://registry.yarnpkg.com/is-what/-/is-what-4.1.16.tgz#1ad860a19da8b4895ad5495da3182ce2acdd7a6f" | ||
integrity sha512-ZhMwEosbFJkA0YhFnNDgTM4ZxDRsS6HqTo7qsZM08fehyRYIYa0yHu5R6mgo1n/8MgaPBXiPimPD77baVFYg+A== | ||
|
||
isarray@^1.0.0: | ||
version "1.0.0" | ||
resolved "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz" | ||
|
@@ -7409,11 +7451,12 @@ openid-client@^5.4.0: | |
object-hash "^2.2.0" | ||
oidc-token-hash "^5.0.3" | ||
|
||
optimism@^0.17.5: | ||
version "0.17.5" | ||
resolved "https://registry.npmjs.org/optimism/-/optimism-0.17.5.tgz" | ||
integrity sha512-TEcp8ZwK1RczmvMnvktxHSF2tKgMWjJ71xEFGX5ApLh67VsMSTy1ZUlipJw8W+KaqgOmQ+4pqwkeivY89j+4Vw== | ||
optimism@^0.18.0: | ||
version "0.18.0" | ||
resolved "https://registry.yarnpkg.com/optimism/-/optimism-0.18.0.tgz#e7bb38b24715f3fdad8a9a7fc18e999144bbfa63" | ||
integrity sha512-tGn8+REwLRNFnb9WmcY5IfpOqeX2kpaYJ1s6Ae3mn12AeydLkR3j+jSCmVQFoXqU8D41PAJ1RG1rCRNWmNZVmQ== | ||
dependencies: | ||
"@wry/caches" "^1.0.0" | ||
"@wry/context" "^0.7.0" | ||
"@wry/trie" "^0.4.3" | ||
tslib "^2.3.0" | ||
|
@@ -8255,6 +8298,11 @@ regjsparser@^0.9.1: | |
dependencies: | ||
jsesc "~0.5.0" | ||
|
||
rehackt@^0.1.0: | ||
version "0.1.0" | ||
resolved "https://registry.yarnpkg.com/rehackt/-/rehackt-0.1.0.tgz#a7c5e289c87345f70da8728a7eb878e5d03c696b" | ||
integrity sha512-7kRDOuLHB87D/JESKxQoRwv4DzbIdwkAGQ7p6QKGdVlY1IZheUnVhlk/4UZlNUVxdAXpyxikE3URsG067ybVzw== | ||
|
||
remark-parse@^11.0.0: | ||
version "11.0.0" | ||
resolved "https://registry.npmjs.org/remark-parse/-/remark-parse-11.0.0.tgz" | ||
|
@@ -8876,6 +8924,13 @@ supercluster@^8.0.0, supercluster@^8.0.1: | |
dependencies: | ||
kdbush "^4.0.2" | ||
|
||
"superjson@^1.12.2 || ^2.0.0": | ||
version "2.2.1" | ||
resolved "https://registry.yarnpkg.com/superjson/-/superjson-2.2.1.tgz#9377a7fa80fedb10c851c9dbffd942d4bcf79733" | ||
integrity sha512-8iGv75BYOa0xRJHK5vRLEjE2H/i4lulTjzpUXic3Eg8akftYjkmQDa8JARQ42rlczXyFR3IeRoeFCc7RxHsYZA== | ||
dependencies: | ||
copy-anything "^3.0.2" | ||
|
||
supports-color@^5.3.0: | ||
version "5.5.0" | ||
resolved "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz" | ||
|