Test on this url
http://getapple.net/phpbb/banners.js
It return 304, File not modified.
I have once enable plugin "mod_expires" and set up js to cache for 1 month.
But now i want to reset the rules. I try to comment this line
ExpiresByType application/javascript "access 1 month"
and then restart apache.
But the file still load from cache. (Response Header return 304 in Chrome Browser)
But after i run this
curl -I http://getapple.net/phpbb/banners.js
in command line, the result are
HTTP/1.1 200 OK
Date: Sun, 10 May 2015 14:51:59 GMT
Server: Apache/2.4.7 (Ubuntu)
Last-Modified: Sun, 10 May 2015 14:34:14 GMT
ETag: "9dd2-515bb27cf250a"
Accept-Ranges: bytes
Content-Length: 40402
Vary: Accept-Encoding
Content-Type: application/javascript
I don't know what i did wrong. Please suggest how to get the updated version of my file via url.
Thanks a lot.
When you send Expires header to browser, it will cache your response and only check for newer version after the expiration date has passed. Since browser won't check for newer version, changing your server settings won't affect browser's cached data. If you made some mistake in your script or there is an update, you can use query string to force browsers to ask for your script.
Assume this is your current script:
<script src="http://getapple.net/phpbb/banners.js" ></script>
What you need to do:
<script src="http://getapple.net/phpbb/banners.js?v=20150510" ></script>
Since URL is not the same, browser will ask for the one with query string and your new settings will be applied!
Related
I have website setup to serve static files via CDN. I'm using cloudfront CDN. When i open my website on mobile using UC Browser. it only loads the HTML page and do not accepts the files(images,.js,.css, etc..) delivered by CDN.
However When I turn of CDN and serve files directly then my sites work without any problem. The problem occurs when ad-block mode is On in UC Browser.
about 80% visitors of my site uses UC browser and I don't want to turn off CDN. Also I've seen some websites that uses CDN and works fine in UC browser with ad-block mode turned On.
here are the headers returned by CDN for js file
age: 237446
cache-control: public, max-age=2592000
content-encoding: gzip
content-type: application/javascript
date: Mon, 24 Sep 2018 10:51:26 GMT
last-modified: Sat, 15 Sep 2018 08:56:57 GMT
server: Apache/2.4.18 (Ubuntu)
status: 200
vary: Accept-Encoding
via: 1.1 b5fbf0f0a39109b04a248c9bb51b5d6a.cloudfront.net (CloudFront)
x-amz-cf-id: IoyQ_74Qgo9nqBRJN0YHkTZk-atMfRscw50y27LxPiMuUG0VeQUxHA==
x-cache: Hit from cloudfront`
i am using Apache as backend server and nginx as frontend server. I need to make PDF files downloadable (at this moment they are opening in a browser window).
Here's a link:
link
Here's what i have tried so far in my .htaccess file:
<FilesMatch "\.(pdf)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
Didn't work, just opens the file in a browser.
AddType application/force-download pdf
Didn't work.
AddType application/octet-stream .pdf
Didn't work.
UPDATE
Tried: wget --server-response -O /dev/null http://domain.com/files/teltomat.pdf
And got response:
HTTP request sent, awaiting response...
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 24 Sep 2014 17:40:54 GMT
Content-Type: application/pdf
Content-Length: 3116445
Last-Modified: Wed, 24 Sep 2014 13:28:07 GMT
Connection: keep-alive
Keep-Alive: timeout=60
ETag: "5422c6e7-2f8d9d"
Expires: Thu, 31 Dec 2037 23:55:55 GMT
Cache-Control: max-age=315360000
Accept-Ranges: bytes
Length: 3116445 (3,0M) [application/pdf]
Saving to: ‘/dev/null’
You could try the HTML5 solution of adding a "download" instead of "target":
link
As it looks like the server's end is doing the right thing (by making the disposition "attachment") but maybe the browser is deciding on its own that it can handle PDF's inline and opens a new window instead.
I am starting to learn about http correctly.
I am working in lamp stack.
On the command line i am requesting a local page which will be served with apache to see the headers that are returned.
curl -i local.testsite
The page i am requesting has no content and i am not setting any headers but there are already a lot of headers sent in the response such as:
HTTP/1.1 200 OK
Date: Thu, 17 Jan 2013 20:28:52 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.3.10-1ubuntu3.4
Vary: Accept-Encoding
Content-Length: 0
Content-Type: text/html
So if i am not setting these, does apache set these automatically?
Yes Apache is setting those by default. By the way, if you only care about the headers, you should use
curl -I local.testsite
-I returns the headers only (HTTP HEAD request), such that even if you had content on the page you would only get the header.
Some are set by PHP:
The X-Powered-By header is set by the expose_php INI setting.
The Content-Type header is set by the default_mimetype INI setting.
The others are set by Apache:
The Server header is set by the ServerSignature directive.
The Vary: Accept-Encoding header is usually sent when mod_deflate is enabled.
Date and Content-Length are not configurable as they are part of the HTTP spec. Date is included as a MUST (except under some conditions) and Content-Length as a SHOULD.
See also How to remove date header from apache? and How to disable the Content-Length response header with Apache?.
I have a small dynamic site implemented in mod_python. I inherited this, and while I have successfully made relatively minor changes to its content and logic, with HTTP caching I'm out of my depth. The site works fine already, so this isn't "the usual question" about how to disable caching for a dynamic site.
My problem is there is one large banner image on each page (the same image from same URL on each page) which accounts for ~90% of site bandwidth but which so far as I can tell isn't being cached; as I browse the site every time I click to a new page (or back to a previously visited one) there it is downloading it yet again.
If I wget the banner's image URL (to see the headers) I see:
$ wget -S http://example.com/site/gif?name=banner.gif
--2012-04-04 23:02:38-- http://example.com/site/gif?name=banner.gif
Resolving example.com... 127.0.0.1
Connecting to example.com|127.0.0.1|:80... connected.
HTTP request sent, awaiting response...
HTTP/1.1 200 OK
Date: Wed, 04 Apr 2012 22:02:38 GMT
Server: Apache/2.2.14 (Ubuntu)
Content-Location: gif.py
Vary: negotiate
TCN: choice
Set-Cookie: <blah blah blah>
Connection: close
Content-Type: image/gif
Length: unspecified [image/gif]
Saving to: `gif?name=banner.gif'
and the code which is serving it up isn't much more than
req.content_type = 'image/gif'
req.sendfile(fullname)
where fullname is a file-path munged from the request's name parameter.
My question is: is there some quick fix along the lines of setting an Expires: or Vary: field in the image's request response which will result in clients being less keen to repeatedly download it ?
The site is hosted on Ubuntu 10.04 and doesn't have any non-default apache mods enabled other than rewrite.
I note that most (not all) of the site pages' headers themselves do contain
Pragma: no-cache
Cache-Control: no-cache
Expires: -1
Vary: Accept-Encoding
(and the original site author has clearly thought about this as no-cache is applied selectively to non-static content pages). I don't know enough about caching to know whether this somehow poisons the included .gif IMG into being reloaded every time too though.
I don't know if my answer can help you or not, but I post it anyway.
Instead of serving image files from within python application, you can create another virtualhost within apache (on same server) just to serve static and image file. In your python application, you can embed image likes this
<img src="http://img.yoursite.com/banner.gif" alt="banner" />
With separate virtualhost, you can add various header to various content type using mode header, or add another caching layer for your static file.
Hope this help.
I need to minimize Apache HTTP response headers, by now i reduced them as following
HTTP/1.1 200 OK
Date: Thu, 25 Mar 2010 21:57:41 GMT
Server: Apache
Content-Type: text/html
I'd like to know if there is a way to disable Date and Server header, only for a certain virtual host.
Thank you!
The Date header is required at part of the HTTP standard. You can't remove it without being non-compliant with the http standard, so apache doesn't generally allow that.