首页 > 其他分享 >[Web] Preload & Prefetch

[Web] Preload & Prefetch

时间:2022-08-26 20:47:39浏览次数:89  
标签:Preload Web resource preload Prefetch using true resources

Source: https://javascriptpatterns.vercel.app/patterns/performance-patterns/browser-hints

 

Prefetch

The `prefetch` browser hint can be used to fetch resouces that maybe needed some time soon, but not immediately on the initial load. 

This can be the case on subsequent requests or page navigations that a user is likely to make.

We can prefetch a resource by explicitly adding it to the head of the html document.

<link rel="prefetch" href="./about.bundle.js" />

If you're using Webpack, you can prefetch it dynamically by using the /* webpackPrefetch: true */ magic comment.

const About = lazy(() => import(/* webpackPrefetch: true */ "./about"));

 

Peload

The preload browser hint can be used to fetch resources that are critical to the current navigation, such as fonts or images are instantly (not longer than 3 seconds after the initial load) visible on a landing page.

A preloaded resources gets fetched no matter what condition.

We can preload a resource by explicitly adding it to the head of the html document.

<link rel="preload" href="./search-flyout.bundle.js" />

If you're using Webpack, you can preload it dynamically by using the /* webpackPreload: true */ magic comment.

const SearchFlyout = lazy(() =>
  import(/* webpackPreload: true */ "./SearchFlyout")
);

Performance: Since preloaded assets will get fetched no matter what, it's important to only preload resources that are actually instantly necessary. In most cases, it's worth either prefetching the resource, or if it's JavaScript, using a script with an async or defer attribute.

  <link href="./script" rel="preload" />
  <script rel="defer" src="./script" />

标签:Preload,Web,resource,preload,Prefetch,using,true,resources
From: https://www.cnblogs.com/Answer1215/p/16629101.html

相关文章

  • 02-web服务器
    02-web服务器概述本文主要介绍web服务器技术web服务使用的主流开发语言ASP:微软开发:国内最早流行的语言在html中嵌入了VB的脚本,ASP+COM在ASP开发中,基本一个页面有......
  • 基于 .NET 6 的轻量级 Webapi 框架 FastEndpoints
    FastEndpoints 是一个基于.NET6开发的开源webapi框架,它可以很好地替代.NETMinimalAPIs和MVC,专门为开发效率而生,带来了全新的开发模式和编码体验。另外对于.N......
  • 生产环境自动备份win服务器所有web项目(IIS+项目代码)
    @echooffrem功能:每月自动备份本服务器所有web项目rem日期:2022.3.10rem制作人:zlrem定义变量Y为备份时间:YYYYMMsety=%date:~0,4%%date:~5,2%rem备份IIS配置C:\Windo......
  • CTFSHOW Web259 SoapClient原生类的反序列化
      index.php   看到该题目第一眼,大脑直接一个简单的想法就是通过访问flag.php添加X-Forwarded-For然后POST发送token数据。但!在本题的环境当中,由于使用了Clou......
  • Google Web Toolkit (GWT) 说明-基本上没有人用了
    GoogleWebToolkit(GWT)是用于构建和优化复杂的基于浏览器的应用程序的开发工具包。Google的许多产品都使用GWT,包括GoogleAdWords和Orkut。GWT是一个开源的、......
  • 代码审计(Java)——WebGoat_RequestForgeries
    一、Cross-siteRequestForgeries1.level3 这里的level3,就是限制了Referer的参数值为空或者是不等于host即可,单纯为了教学而设计的题目,没啥可说的~因......
  • Webpack 4(一)
    模块打包工具的由来Web1.0编写静态页面表单验证和动效Web2.0之AJAX管理数据和用户进行数据交互大前端开发PC端移动端小程序APP现代Web开发“问题”......
  • Webstorm 开发格式化时之 rpx 出现空格解决方案
    Webstorm开发格式化时之rpx出现空格解决方案当写好程序后,格式化如下:rpx前自动出现空格,或者一直是红色波浪线使用插件wechat-miniprogram-plugin......
  • 基于 .NET 6 的轻量级 Webapi 框架 FastEndpoints
    大家好,我是等天黑。FastEndpoints 是一个基于.NET6开发的开源webapi框架,它可以很好地替代.NETMinimalAPIs和MVC,专门为开发效率而生,带来了全新的开发模式和编......
  • ctfshow 萌新web系列--2
    <html><head><title>ctf.show萌新计划web1</title><metacharset="utf-8"></head><body><?php#包含数据库连接文件include("config.php");#判断get提......