I have a slideshow that I preview (custom html/js) and to make sure that I get the most recent version from the DB every time I start the slideshow preview, I have these cache statements in my html file
<!DOCTYPE html>
<!-- preview:[true]-->
<HEAD>
<title>screen</title>
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
However sometimes I still need to empty out the browser cache in order to get the most recent updates.
Is there anything else I can put in the head of my html file to prevent browsers from caching this for me? Chrome is what I mainly use, and where I have sometimes experienced this effect, but I would like a generic answer for all browsers.
---------------- UPDATE -------------------
So I included some cache control headers (thanks arkascha) but am still a bit suspicious =)
Here is what I added to my response (php/sym2)
$response->expire();
$now = new \DateTime("now");
$response->setCache(array(
'last_modified' => $now,
'max_age' => 0,
's_maxage' => 0,
'private' => true,
));
And that gives me the following Response headers
Cache-Control:max-age=0, private, s-maxage=0
Connection:Keep-Alive
Content-Type:text/html; charset=UTF-8
Date:Wed, 31 May 2017 08:41:19 GMT
Keep-Alive:timeout=5, max=100
Last-Modified:Wed, 31 May 2017 08:41:20 GMT
Server:Apache/2.2.25 (Unix) mod_ssl/2.2.25 OpenSSL/0.9.8zh DAV/2 PHP/5.5.3
Transfer-Encoding:chunked
X-Powered-By:PHP/5.5.3
... and Request Headers displays as:
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:sv-SE,sv;q=0.8,en-US;q=0.6,en;q=0.4
Cache-Control:max-age=0
Connection:keep-alive
Cookie:main=1111111; PHPSESSID=70c2e1a6f81a9d3dad59ed908f25b585
Host:localhost
If-Modified-Since:Wed, 31 May 2017 08:40:18 GMT
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
But on my network tab (chrome) I still see a lot of "from memory cache" and "from disk cache" in the "size" column for different resources (what is the difference between those two by the way?).
Does the http header only affect the current page and not the associated resources such as .json files?
Related
I have a logon link on my homepage that shows when a user is logged out. When they are logged in it instead shows the link to my dashboard. This is handled server side and come from server in the HTML.
I have an Issue when a user follows this sequence:
loads homepage
clicks login
logs in and is directed to dashboard
clicks home link and is brought back to homepage
When they do this the homepage is loaded from local cache and still displays the log in link instead of the dashboard link.
If I hit refresh in the browser then it loads the new page with correct link.
I have tried adding the following headers to the HTML:
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
But this doesn't help.
In network tab this is the response headers when loading th page logged out:
accept-ranges: bytes
content-encoding: gzip
content-length: 10290
content-type: text/html
date: Sun, 19 Sep 2021 03:29:38 GMT
etag: "6146829a-2832"
last-modified: Sun, 19 Sep 2021 00:21:46 GMT
referrer-policy: no-referrer-when-downgrade
server: nginx/1.19.5
I am testing in latest version of chrome.
Why does clicking home link load from cache instead of getting the new page?
Basically I have:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="main.css"/>
by doing this I get a console error saying: main.css was not loaded because its MIME type, “text/html”, is not “text/css”.
through sniffing my browser network tab, It appears that the request is made as text/css but the response comes as text/html.
Request Headers (0.361 KB):
User-Agent: "Mozilla/5.0 (X11; linux x86_64; rv:52.0) gecko/20100101"
Accept: "text/css,*/*;q=0.1"
Accept-language: "en-US, e;q=0.5"
Accept-Encoding: "gzip, deflate"
Response Header (0.123 KB):
Content-Type: "text/html;charset=ISO-8859-1"
Date:"FRI 20 Oct 2017 ..."
Transfer-Encoding: "chunked"
FYI: This stylesheet is request in mutiple pages, at the other pages it works but not here.
Much regards
Arabic user data that was submitted from a website form occasionally ends up Mojibake in our database. A user would type something like:
الإعلان العالمى لحقوق الإنسان
in an input form and the post is received by a server and stored in a database. When we retrieve the message from the database, it reads:
الإعلان العالمى Ù„Øقوق الإنسان
The form is in an embedded iframe page with these tags:
<!DOCTYPE HTML>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
<!-- other header elements -->
</head>
<body>
<form accept-charset="utf-8" action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="post">
<!-- other body elements -->
</body>
</html>
A post generate these request headers
Accept */*
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Cache-Control no-cache
Connection keep-alive
Content-Length 543
Content-Type application/x-www-form-urlencoded; charset=UTF-8
Host www.salesforce.com
Origin [ -- redacted -- ]
Pragma no-cache
Referer [ -- redacted -- ]
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:28.0) Gecko/20100101 Firefox/28.0 FirePHP/0.7.4
x-insight activate
And receives these response headers
HTTP/1.1 200 OK
Date: Fri, 25 Apr 2014 09:15:49 GMT
Cache-Control: private
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
I have no control over the server configuration of the machine serving the form or the server processing the form data.
Is there anything more I can do in the page markup that can prevent the problem? Are there known user agents which would ignore the accept-charset attribute?
Since the character scramble only happens occasionally, what is the best way to try and replicate / isolate the problem?
Thanks!
I know this question has been asked multiple times before, but the solutions posted are not working for me.
I have put the following in the <head> tag, to no avail:
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
I also saw some mention about the onunload attribute and the bfcache in browsers, so I added that to the <body> tag, also to no avail.
The response headers from my server contain:
Cache-Control max-age=0, private, must-revalidate
Would appreciate it if someone could point me in the right direction here - what am I doing wrong?
Answering my own question. As it turns out, setting the following response headers (as opposed to META tags) worked for me:
Cache-Control private, no-store, max-age=0, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma no-cache
Expires Fri, 01 Jan 1990 00:00:00 GMT
If you're working in Rails like I am, you can do this easily by putting the following in an ApplicationController before_filter callback:
response.headers["Cache-Control"] = "private, no-store, max-age=0, no-cache, must-revalidate, post-check=0, pre-check=0"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
Using the back button will use the cache as #kindall said. It really depends on what you don't want cached.
Instead of encouraging users from using the back button can you structure the page navigation so that the user can always get to where they want without having to use a back button?
The stuff you don't want cached can you load it dynamically via ajax?
You can reload the logged In page with reload() after the session is being terminated in the http() fun, this updates the local cache. Since your session has ended the reload will take you to the login page. Even if you press the browser back button the login page remains, because the local cache is updated.
I am using CGI::Application with UTF-8 data.
In the HTML have I set encoding to UTF-8 like so
<!DOCTYPE html>
<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
but the output is treated as latin1, as special characters are displayed as 2 characters.
Page Info in Firefox says the page is encoded with ISO-8859-1 despite the HTML header.
I have only been able to find these two posts about the problem, but they are old and very complicated.
Anyone that have solved this problem?
Update: Here are the HTTP header from FireBug.
Response Headers
Date Tue, 26 Apr 2011 09:53:24 GMT
Server Apache/2.2.3 (CentOS)
Connection close
Transfer-Encoding chunked
Content-Type text/html; charset=ISO-8859-1
Request Headers
Host example.com
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:2.0) Gecko/20100101 Firefox/4.0
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-gb,en;q=0.5
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
I noticed that if I force UTF-8 by FireFox->Web Developer->Character Encoding->Unicode (UTF-8), if looks correct.
Your HTTP headers:
Content-Type text/html; charset=ISO-8859-1
… claim the document is encoded as Latin 1. Real HTTP headers take priority over HTML <meta> data.
$webapp->header_add(-type => 'text/html; charset=UTF-8');
… should do the job if I'm reading the documentation correctly.