Hỏi về ý nghĩa của dòng này trong link

Tui đang tập code HTML-CSS trên Visual Studio Code, cài server “Live Server” để deloy. Tui có cho một file HTML link tới một file css trong subfolder như sau:

<link type="text/css" rel="stylesheet" href="./assets/css/styles.css">

Thì bị báo lỗi (trong cùng folder thì không có lỗi này):

Refused to apply style from 'http://127.0.0.1:5500/assets/css/styles.css/' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

Sau một lúc tui phát hiện ra là nếu chỉnh đường dẫn như sau thì sẽ ko bị lỗi nữa:

<link type="text/css" rel="stylesheet" href="./assets/css/styles.css?_cacheOverride=1610623941255">

Vậy cho tui hỏi cái phần ?_cacheOverride=1610623941255 có nghĩa là gì?
Xin cảm ơn.
Tui dùng browser Chrome.

Phần đó được gọi là Cache-busting query. Cách này hay được implement trên nơi có cache các file static (ví dụ như các CDN server).
Cậu có thể tham khảo thêm ví dụ này để biết Cache-busting là gì:

To help better illustrate cache busting, consider the following example to help better explain what is cache busting.

  1. Let’s say that you have a CSS file (e.g. style.css ) and you set the expires value for that file type to 1 year. This means that once cached locally on the user’s browser, the browser won’t check the origin server again for 1 whole year to see if any updates have been made to the file.
  2. Three months down the road you decide to make a change to the style.css file. Therefore if you make the change, and reupload it to the server under the same name, the browser won’t know the difference and will keep delivering the original style.css file .
  3. On the other hand, if you implement cache busting, you would rename the updated file to something like style.v2.css . Therefore once you have updated the page’s HTML to reflect this change, the browser will know that there is a new file that should be retrieved and it will start using it right away.

Using this method you can take advantage of setting high expires values while continuing to deliver the most recently updated changes to visitors.

Original article: https://www.keycdn.com/support/what-is-cache-busting

6 Likes
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?