【问题标题】:Invalidate cache in a Apache server to use GatsbyJS使 Apache 服务器中的缓存无效以使用 GatsbyJS
【发布时间】:2021-03-21 12:18:17
【问题描述】:

我正在尝试使用 Gatsby 在 Apache 服务器中生成的站点来部署我的站点。根据Gatsby docs,缓存控制应该像这样为public/page-data设置

cache-control 标头应该是 cache-control: public, max-age=0, 必须重新验证1

所以我在public/page-data 文件夹中添加了一个.htaccess 文件。由于某种原因,这些文件仍然被缓存,并且出现 http 代码409 冲突错误。

这是.htaccess 文件的内容。

<FilesMatch "\.(html|htm|js|css|php|json)>
FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</FilesMatch>

我做错了吗?有什么方法可以使/public/page-data的缓存失效

更新

我得到 409 的页面是这个

import React from 'react';
import PageContent from '../components/UI/PageContents';
import Layout from '../components/layout';
import SEO from '../components/seo';

const Contact = () => (
  <Layout innerPage="nk-contact" headerText="Contact us">
    <SEO title="Contact us" />
    <PageContent>
      <div className="row">
        <div className="col-md-6">
          <section className="mb-2">
            <h2 data-aos="fade-right">Contact us at</h2>
            {[
              '+91 1111111',
              '+91 2222222',
              '+91 2222222',
              '+91 2222222',
            ].map((number, index) => (
              <span key={`call-${index}`}>
                <a href={`tel:${number}`}>{number}</a>
                <br />
              </span>
            ))}

            <div className="py-1 mb-4">
              <h3 className="pt-3 pb-1 d-block">Email</h3>
              
              
            </div>
          </section>
        </div>
        <div className="col-md-6">
          <section className="mb-1">
            <h3 data-aos="fade-right">Our Timing</h3>
            <p>Office timings: 9.00 am - 6.00 pm.</p>
          </section>
        </div>
      </div>
      <hr />
      <h3 data-aos="fade-left" className="mb-3">
        Our Sales address
      </h3>
      <div className="row">
        <div className="col-md-6">
          <address>
            <strong> xxxxx</strong>
            <br />
            xxxxx
          </address>
        </div>
      </div>
    </PageContent>
  </Layout>
);

export default Contact;

【问题讨论】:

    标签: reactjs apache .htaccess gatsby


    【解决方案1】:

    在每次代码编译 (gatsby build) 中都会重做公用文件夹,因此您的 .htaccess 可能会在每次代码部署中被删除。

    也就是说,你至少有两种方法:

    • 使用像gatsby-plugin-htaccess这样的插件
    • 在static folder 中创建.htaccess。放置在项目根目录中的静态文件夹正在以相同的内部结构(并且没有 Gatsby 的处理或由其转换器处理)转译到 /public,所以如果你在那里放置 /static/.htaccess(或 /static/page-data/.htaccess如果需要)将在编译后出现在公用文件夹中。

    【讨论】:

    • 嗯......事实上,它是联系页面,它将向服务器发送请求,并且 409 问题(即冲突)似乎与 fetch 方法有关。看看它或分享那个页面代码
    • 该页面没有任何抓取。它只是一个简单的jsk页面。我已经用页面源更新了问题
    • 数字从何而来?
    猜你喜欢
    • 2011-06-15
    • 2019-02-25
    • 1970-01-01
    • 1970-01-01
    • 2021-02-05
    • 2016-10-18
    • 2011-09-23
    • 2013-11-26
    • 1970-01-01
    相关资源
    最近更新 更多