Example of disabling browser cache configuration in Vue project

Example of disabling browser cache configuration in Vue project

When releasing a project, you will often encounter the problem of needing to clean up the cache. Here is the actual method to disable the cache for the project.

1. Modify the meta configuration of the index.html file in the public folder

image.png

    <meta http-equiv="pragram" content="no-cache" />
    <meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate" />
    <meta http-equiv="expires" content="0" />

2.vue cli build configuration (for versions below vue3)

Add configuration in vue.config.js

const Timestamp = new Date().getTime()
module.exports = {
  configureWebpack: {
    output: { // Output the name of the file after reconstruction, packaging and compilation [module name. version number (optional). timestamp]
      filename: `[name].${Timestamp}.js`,
      chunkFilename: `[name].${Timestamp}.js`
    },
  },
  css: {
    extract: { // Add timestamp to the name of the CSS file after packaging filename: `css/[name].${Timestamp}.css`,
      chunkFilename: `css/[name].${Timestamp}.css`
    }
  },
}

3. Nginx configuration

Disable nginx cache and let the browser request files from the server each time instead of reading cached files in the browser.

After the program is debugged and launched, you can enable nginx cache to save server bandwidth, reduce some requests, and reduce server pressure.

image.png

Configure the HTML file in the nginx.conf file to add a header by default and not cache the configuration

The following actual project nginx cache configuration

  location ~ .*\.(?:htm|html)$ {
    add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
  }

Nginx static resource cache settings https://www.jb51.net/article/222620.htm

This is the end of this article about the case of disabling browser cache configuration in vue project. For more relevant content about disabling browser cache configuration in vue project, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Vue encapsulates a TodoList example and implements the application of browser local cache
  • Solve the problem of WeChat browser caching site entry files (IIS deploys Vue project)
  • Detailed explanation of Vue server-side rendering browser cache (keep-alive)

<<:  Tutorial on installing Nvidia graphics card driver in Ubuntu 18.04 (with pictures and text)

>>:  Ubuntu 20.04 CUDA & cuDNN Installation Method (Graphical Tutorial)

Recommend

How to use JS to implement waterfall layout of web pages

Table of contents Preface: What is waterfall layo...

Source code reveals why Vue2 this can directly obtain data and methods

Table of contents 1. Example: this can directly g...

Detailed explanation of MySQL batch SQL insert performance optimization

For some systems with large amounts of data, the ...

Linux kernel device driver system call notes

/**************************** * System call******...

Two ways to connect WeChat mini program to Tencent Maps

I've been writing a WeChat applet recently an...

MySQL 5.7 generated column usage example analysis

This article uses examples to illustrate the usag...

Essential conditional query statements for MySQL database

Table of contents 1. Basic grammar 2. Filter by c...

Implementation of TCPWrappers access control in Centos

1. TCP Wrappers Overview TCP Wrappers "wraps...

Understand all aspects of HTTP Headers with pictures and text

What are HTTP Headers HTTP is an abbreviation of ...

Do you know the common MySQL design errors?

Thanks to the development of the Internet, we can...

Use pure JS to achieve the secondary menu effect

This article example shares the specific code of ...

Getting Started with MySQL - Concepts

1. What is it? MySQL is the most popular relation...

Vue gets token to implement token login sample code

The idea of ​​using token for login verification ...