K
K
khipster2016-02-27 04:13:44
PHP
khipster, 2016-02-27 04:13:44

AJAX request downloads file.txt. How to disable caching?

I do not want to use a crutch with adding a random parameter to the request.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
RubaXa, 2016-02-27
@RubaXa

Browsers can safely ignore headers and cache to death, for example, Safari on iOS even caches POST, so the option with a unique key is not such a bad solution. You can only not shove it into the queryString, but make it part of the url (`/path/to/${uniq-id}/my-file.txt`), this will definitely work for all 146%.

R
riot26, 2016-02-27
@riot26

maybe something like this:

<?php
header("Content-Type: content-type text/plain");
header("Expires: Mon, 26 Apr 1989 12:00:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

M
Mark Doe, 2016-02-27
@mourr

Judging by the tags, you need to add something like this to .htaccess

<Files .txt>
    Header unset Cache-Control
</Files>

N
nozzy, 2016-02-28
@nozzy

url: '/path_to_file/file.txt&r=' + (new Date()).getTime();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question