Internet > Web Hosting & Web Design

Embedded CSS in an XML (XHTML5 polyglot XML/HTLM5) web page

(1/1)

Weaver:
Question: Is the following the best way to embed CSS in an XML document that is XHTML5 polyglot format ? - ie the page is both legal, well-formed XML and valid HTML5 and parseable ok as either.


--- Code: ---<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  <head>
    <meta charset="utf-8"/>
    <title>The Title</title>
    <style type="text/css"> /* <![CDATA[ */
  … CSS goes here …

/*]]>*/
    </style>
    </head>
--- End code ---

See also: https://en.wikipedia.org/wiki/CDATA#Use_of_CDATA_in_program_output
   
I have to embed the CSS in this case, realistically. Normally I always always link to CSS in a separate file which is much cleaner and although sometimes slower because of an additional http fetch, on the other hand, in the case where there is more than one web page, linking to CSS can be faster because the separate CSS file may well be cached. Also the CSS could then well be shared by several web pages on a website, which reduces total byte count by avoiding duplication and also increases the likelihood of effective caching of shared CSS files.

In this case though I have no easy way of linking to a separate CSS file (without some very ugly tricks) because I have no available real URL for the page as it's not on the web and is just generated locally. I'm doing this under iOS, which doesn't appear to have file: URLs as eg Windows does.


One more question: Is there really an need at all to declare the charset as UTF8 with that meta element given that the web page in question will always be UTF8 encoded anyway?  - I never use anything other than UTF8. Isn’t UTF8 just the universal default assumption for the web in any event?

Navigation

[0] Message Index

Go to full version