Kitz ADSL Broadband Information
adsl spacer  
Support this site
Home Broadband ISPs Tech Routers Wiki Forum
 
     
   Compare ISP   Rate your ISP
   Glossary   Glossary
 
Please login or register.

Login with username, password and session length
Advanced search  

News:

Author Topic: Embedded CSS in an XML (XHTML5 polyglot XML/HTLM5) web page  (Read 3774 times)

Weaver

  • Senior Kitizen
  • ******
  • Posts: 11459
  • Retd s/w dev; A&A; 4x7km ADSL2 lines; Firebrick

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: [Select]
<!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>

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?
Logged