phantomCoder
phantomCoder

Reputation: 1587

Invalidate cache in a Apache server to use GatsbyJS

I am trying to deploy my site with is generated by Gatsby in a Apache server. As per Gatsby docs the cache control should be set like this for public/page-data

The cache-control header should be cache-control: public, max-age=0, must-revalidate1

So I added a .htaccess file in public/page-data folder. For some reason the files are still cached and getting error with http code 409 conflict.

This is the .htaccess files contents.

<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>

Am I doing anything wrong? Is there any way to invalidate cache for /public/page-data

Update

The page in which I am getting 409 is this

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;

Upvotes: 1

Views: 487

Answers (1)

Ferran Buireu
Ferran Buireu

Reputation: 29315

The public folder is redone in every compilation of code (gatsby build) so probably, your .htaccess is being deleted in each code deployment.

Said that, you have at least 2 approaches:

  • Using some plugin like gatsby-plugin-htaccess
  • Create the .htaccess in the static folder. The static folder, placed in the root of your project, is being transpiled with the same internal structure (and without Gatsby's treatment or processing by its transformers) to the /public, so if your place there a /static/.htaccess (or /static/page-data/.htaccess if you want) will be present in the public folder once compiled.

Upvotes: 1

Related Questions