我有一个简单的标记。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="prefetch" href="page2.html">
<link as="script" rel="prefetch" href="./src/script2.js">
</head>
<body>
<p>Let's check</p>
<a href="page2.html">Go to page 2 where script2 is there</a>
<script src="./src/script1.js"></script>
</body>
</html>
在这里,我预取了第二个脚本script2.js。它已成功预取,但是当我单击第 2 页链接时,我有我的脚本标签script2.js,再次下载了 script2 它没有从预取缓存中获取它。
这是page2.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<p>This is page 2</p>
<script src="./src/script2.js"></script>
</body>
</html>