client: preload resource

This commit is contained in:
fantasticit 2022-06-02 23:32:41 +08:00
parent 4d5f745983
commit c4dfe1155d
2 changed files with 18 additions and 0 deletions

View File

@ -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;

View File

@ -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);
}