【问题标题】:Next.js <Image /> component slow on Netlify, fast on VercelNext.js <Image /> 组件在 Netlify 上慢,在 Vercel 上快
【发布时间】:2021-06-27 22:55:28
【问题描述】:

我有一个相对简单的 Next.js 应用程序,并且正在使用 Next.js 的 &lt;Image /&gt; 组件来渲染两个小图像,如下所示:

<Row className="justify-content-center m-0 mt-3 text-center">
  <Col xs={4} md={3} lg={2} className="pr-xs-0  pr-sm-5 pl-0">
    <Image
      src="/assets/images/logo1.png"
      alt="Logo etc1"
      width={320}
      height={150}
    />
  </Col>
  <Col xs={4} md={3} lg={2} className="pl-xs-0 pr-0 pl-sm-5">
    <Image
      src="/assets/images/logo2.jpg"
      alt="Logo etc2"
      width={320}
      height={150}
    />
  </Col>
</Row>

这两个小图像(每个大约 50Kb)在开发过程中立即加载,但在 Netlify 上部署时它们花费的时间非常可笑(最多 4 秒!!)。

部署到 Vercel 的完全相同的存储库立即呈现图像。

值得一提的是,使用普通的 html &lt;img /&gt; 标签在 Vercel 和 Netlify 上渲染它们的速度都非常快,但我很困惑地看到,当使用 Next.js 延迟加载时,这些不起眼的图像需要多长时间才能加载到 Netlify ' &lt;Image /&gt; 组件。

我有什么遗漏的吗?

【问题讨论】:

    标签: reactjs next.js netlify


    【解决方案1】:

    Vercel 在您的应用程序前面使用某种服务器,用于在使用 next/image 时优化图像。

    尝试使用 Next.js https://github.com/netlify/netlify-plugin-nextjs 的 Netlify 插件。 不过还是有一些问题:https://github.com/netlify/netlify-plugin-nextjs/issues/155

    【讨论】:

    • 谢谢,但这是几天前部署的,引用:As of v3.0.0, all new sites deployed to Netlify with Next.js will automatically install this plugin for a seamless experience deploying Next.js on Netlify!。该插件已经安装,事实证明,如果我想这样做,它会弹出This plugin has already been installed on &lt;app&gt;. Please choose another site or visit your selected site’s plugins page.
    猜你喜欢
    • 1970-01-01
    • 2021-11-17
    • 2022-12-17
    • 1970-01-01
    • 1970-01-01
    • 2021-05-31
    • 2021-09-21
    • 1970-01-01
    • 2021-06-14
    相关资源
    最近更新 更多