mirror of https://github.com/fantasticit/think.git
client: preload resource
This commit is contained in:
parent
4d5f745983
commit
c4dfe1155d
|
@ -10,6 +10,7 @@ import App from 'next/app';
|
||||||
import Head from 'next/head';
|
import Head from 'next/head';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Hydrate, QueryClient, QueryClientProvider } from 'react-query';
|
import { Hydrate, QueryClient, QueryClientProvider } from 'react-query';
|
||||||
|
import { preload } from 'tiptap/preload';
|
||||||
|
|
||||||
class MyApp extends App<{ isMobile: boolean }> {
|
class MyApp extends App<{ isMobile: boolean }> {
|
||||||
state = {
|
state = {
|
||||||
|
@ -36,6 +37,10 @@ class MyApp extends App<{ isMobile: boolean }> {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
preload();
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { Component, pageProps, isMobile } = this.props;
|
const { Component, pageProps, isMobile } = this.props;
|
||||||
const { queryClient } = this.state;
|
const { queryClient } = this.state;
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
import { DOCUMENT_COVERS } from '@think/constants';
|
||||||
|
|
||||||
|
const preloadImage = (url) => {
|
||||||
|
requestIdleCallback(() => {
|
||||||
|
const image = document.createElement('img');
|
||||||
|
image.src = url;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export function preload() {
|
||||||
|
if (typeof window === 'undefined') return;
|
||||||
|
DOCUMENT_COVERS.forEach(preloadImage);
|
||||||
|
}
|
Loading…
Reference in New Issue