How to handle meta elements not validating in HTML5? - validation

In HTML5, some meta elements do not validate (yet?) like:
<meta http-equiv="x-ua-compatible" content="ie=emulateie7;chrome=1">
<meta http-equiv="imagetoolbar" content="no">
Are Conditional Comments an appropriate solution here resp. will meta elements still work as expected?
<!--[if IE]><meta http-equiv="x-ua-compatible" content="ie=emulateie7;chrome=1"><![endif]-->
<!--[if lt IE 7]><meta http-equiv="imagetoolbar" content="no"><![endif]-->
Using a .htaccess file instead of meta elements (not always possible unfortunately), would this be the right way to go?
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
# BrowserMatch MSIE ie OR?
BrowserMatch MSIE emulate_ie7
# Header set X-UA-Compatible "IE=EmulateIE7" env=ie OR?
Header set X-UA-Compatible "IE=EmulateIE7" env=emulate_ie7
BrowserMatch chromeframe gcf
Header append X-UA-Compatible "chrome=1" env=gcf
</IfModule>
</IfModule>
Thanks!

Personally for the "x-ua-compatible" tag, i went for the .htaccess directive. I followed the html5boilerplate template:
# ----------------------------------------------------------------------
# Better website experience for IE users
# ----------------------------------------------------------------------
# Force the latest IE version, in various cases when it may fall back to IE7 mode
# github.com/rails/rails/commit/123eb25#commitcomment-118920
# Use ChromeFrame if it's installed for a better experience for the poor IE folk
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
BrowserMatch MSIE ie
Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie
</IfModule>
</IfModule>
<IfModule mod_headers.c>
# Because X-UA-Compatible isn't sent to non-IE (to save header bytes),
# We need to inform proxies that content changes based on UA
Header append Vary User-Agent
# Cache control is set only if mod_headers is enabled, so that's unncessary to declare
</IfModule>

You can register additional pragma directives:
Extensions to the predefined set of pragma directives may, under certain conditions, be registered in the WHATWG Wiki PragmaExtensions page.
Conformance checkers are then required to recognise them:
Conformance checkers must use the information given on the WHATWG Wiki PragmaExtensions page to establish if a value is allowed or not: values defined in this specification or listed on the aforementioned page must be accepted, whereas values not listed in either this specification or on the aforementioned page must be rejected as invalid.
That may be hard work though, don't know if there's any reason why these headers haven't been listed before but I guess you'll find out if you try it :)
Your .htaccess looks OK according to the MS docs, there may be some variations depending on what version of Apache you're on, but probably the best way to check is to try it and see.

Related

How to set page header cf-cache-status: HIT?

I have set the page header to the public by htaccess file.
<ifModule mod_headers.c>
<filesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|css|js)$">
Header set Cache-Control "max-age=31536000, public"
</filesMatch>
<filesMatch "\\.(html|htm|php)$">
Header set Cache-Control "max-age=31536000, public"
</filesMatch>
</ifModule>
But still, it is showing cf-cache-status: as DYNAMIC for the static HTML page too. Please let me know if there is an additional setting at Cloudflare or the website header.
I'd recommend to review the Default Cache Behaviour documentation page which explains how the Cloudflare Cache works and how to configure it to cache (or bypass caching) different resources. To summarise:
By default only specific file extensions are cached
You can set specific Page Rules to override the default behaviour
You can also use Cloudflare Workers to achieve a customized caching result
You can also use Cache-Control headers, as long as the resource is deemed cacheable (see above)

Issue with manifest/appcache files

I'm looking to declare an offline file that I can use for an iPad site. I believe I must be missing something in the setup as it doesn't seem to work correctly as I understand it. Here is what I have...
index page:
<!doctype html>
<html lang="en" manifest="/cache.appcache">
.htaccess
AddType text/cache-manifest .appcache
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/cache-manifest "access plus 0 seconds"
</IfModule>
cache.appcache
CACHE MANIFEST
CACHE:
/index.php
/img/img.jpg
/img/img#2x.jpg
/inc/script.php
/inc/styles.php
NETWORK:
# All URLs that start with the following lines
# are whitelisted.
FALLBACK:
Here are the steps I go through:
I navigate to the page and confirm that there are no errors and that
the url to the cache.appcache along with the items inside it are
linked correctly.
I navigate through the sites pages to confirm everything is
functioning as expected. No errors seen.
I turn off the Ethernet.
I am able to move through pages I previously setup, however, if I
hit refresh the pages all break and I can't get back to the site.
I may be misunderstanding how this is supposed to work for "offline" mode, but this seems incorrect to me.

Cache browser images if no file extension provided

When a browser requests a jpg and the server returns the data but not as a reference to a jpg file but rather sends the jpg data itself, is it possible for the browser to cache the data?
For example:
http://www.somewebsite.com/image/abc
This uri returns jpg data. Is there some way to get the browser to cache the data it receives to avoid having to request it again?
I just attempted to debug your example but received an Account Suspended. Webmaster, please, contact support. page!
So as I am working blind can I suggest researching the header('Expires: SOME DATA HERE') function in PHP (I assume you are using PHP).
If the solution does not lie there you can also use .htaccess to set the headers using
<IfModule mod_expires.c>
ExpiresActive On
############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
ExpiresDefault "access plus 1 year"
</FilesMatch>
</IfModule>
This example taken from http://www.robertwent.com/blog/servers-and-hosting/45-set-expires-headers-in-htaccess
Ultimately it is the headers that tell the browser how you advise the content is cached. What the browsers actually does can sometimes be surprising.

Trying To "Cookie-Free" A Sub-domain Using .htaccess, But Doesn't Work

Yes, I have searched a lot, here and there, and this is the closest I've found that I thought could actually work. But it doesn't.
<IfModule mod_headers.c>
<FilesMatch "\\.(ico|x-icon|js|css|jpg|jpeg|png|gif|swf|pdf)$">
Header unset Cookie
Header unset Set-Cookie
Header unset ETag
FileETag None
</FilesMatch>
</IfModule>
Pretty clear it should be that I am trying to cookie-free the static files served by a sub-domain, and remove the ETag header on those static files. The ETag thing works fine, but I am unable to unset the cookies.
FYI, Wordpress is installed on example.com (NOT www.example.com; www.example.com redirects to example.com), which is not cookie-free. And i.example.com serves the static files. I want to make i.example.com cookie-free. Is it at all possible to make a subdomain cookie-free when the non-www tld is not cookie-free? (I also see that it's the reason why many suggest using www.tld).
Why you remove the ETag for this files? I would suggest to set this:
FileETag MTime Size
so the browsers, proxies, etc. knows, if a cached file was changed or not.
This speeds up the site a little bit on further visits.
Maybe you set the cookies in the request header so you have to use "RequestHeader unset Cookie" like so:
<IfModule mod_headers.c>
<FilesMatch "\\.(ico|x-icon|js|css|jpg|jpeg|png|gif|swf|pdf)$">
Header set Pragma "public"
Header append Cache-Control "max-age=290304000, public"
RequestHeader unset Cookie
Header unset Cookie
Header unset Set-Cookie
</FilesMatch>
</IfModule>

URL Rewritten and Cache control apache htaccess

I have a page index.php which depending on the arguments provided generates different output.
Using mod_rewrite i have those files a a.htm, b.htm and c.htm .
Now, i want these particular 4 Files (or URLs actually) to be cached locally,
for that i have tried
<FilesMatch "(a\.htm|b\.htm|c\.htm)$">
FileETag None
Header set Cache-Control "max-age=7200, public, must-revalidate"
</FilesMatch>
But it doesn't work.
how do we go about this issue ?
RewriteEngine on
RewriteRule index.htm index.php
<FilesMatch "index.htm">
FileETag None
Header set Cache-Control "max-age=7200, public, must-revalidate"
</FilesMatch>
This is a sneak peak of what i have right now. But in the long run there will be lots of files and rewritten url's. so i want to add cache headers via htaccess . hope it makes sense !

Resources