【问题标题】:Preload Image in html gives warning messagehtml中的预加载图像给出警告消息
【发布时间】:2020-03-09 09:07:48
【问题描述】:

使用link preload预加载要在页面中使用的图像

<link rel="preload" href="http://shmdhussain.github.io/WebTest/test_img/blue.png" 
crossorigin="anonymous" as="image">

但在浏览器中收到警告为

已找到“https://shmdhussain.github.io/WebTest/test_img/blue.png”的预加载,但未使用,因为请求凭据模式不匹配。考虑看看 crossorigin 属性。

我希望它可以工作,但我看到同一资源(图像)的两次下载

查看此演示https://hussain-test.glitch.me/,打开控制台查看警告,提前感谢您的帮助。

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0" />
  <title>HTML BolierPlate</title>
  <link rel="preload" href="https://shmdhussain.github.io/WebTest/test_img/blue.png" crossorigin="anonymous" as="image">
  <style>
    .font32 {
      font-size: 32px
    }
  </style>
</head>
<body>
  Welcome to BoilerPlate!!!
  <p>
    <img src="https://shmdhussain.github.io/WebTest/test_img/blue.png">
  </p>
</body>
</html>

【问题讨论】:

  • 我没有看到任何警告。

标签: html preload


【解决方案1】:

预加载图像时无需用户跨域!图片不需要 CORS

只需删除跨域

使用 crossorigin,您将看到一个失败的预加载和一个成功的加载

【讨论】:

    猜你喜欢
    • 2015-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-21
    相关资源
    最近更新 更多