Jump to content
Sign in to follow this  
Guest FirefoxRocks

Omitting Quotation Marks

Recommended Posts

Guest FirefoxRocks

I can't believe I'm asking this, but is it safe to omit quotation marks around attribute values in HTML if the attribute value only contains alphanumeric characters, hyphens and periods?I know that in HTML 4.01 and HTML 5 attribute values do not need quotation marks around them unless containing other than alphanumeric characters, hyphens and periods, but is it safe to do this?The reason is smaller unprocessed file size (because I have to escape the quotation marks in PHP), and also less bandwidth required to transfer the files (on FTP and via HTTP).

Share this post


Link to post
Share on other sites

You would save little more than 40 bytes by omitting quotation marks on the attribute values that allow it.You can use attributes without quotes as long as they follow the pattern given here: http://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameStartCharI personally prefer to put quotes on all my attributes.

Share this post


Link to post
Share on other sites
Guest FirefoxRocks
You would save little more than 40 bytes by omitting quotation marks on the attribute values that allow it.You can use attributes without quotes as long as they follow the pattern given here: http://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameStartCharI personally prefer to put quotes on all my attributes.
Actually I would probably save an average of 250 bytes per page by doing this because most of my attributes are alphanumeric. A minimum of 100 bytes would be saved because for each pair of quotes dropped I save 2 bytes. And apparently I forgot underscores and colons in the list of allowable values (but I thought that W3C validator rejected unquoted underscores, gotta test again I guess):
In certain cases, authors may specify the value of an attribute without any quotation marks. The attribute value may only contain letters (a-z and A-Z), digits (0-9), hyphens (ASCII decimal 45), periods (ASCII decimal 46), underscores (ASCII decimal 95), and colons (ASCII decimal 58). We recommend using quotation marks even when it is possible to eliminate them.
http://www.w3.org/TR/1999/REC-html401-1999...ut.html#h-3.2.2

Share this post


Link to post
Share on other sites
I can't believe I'm asking this, but is it safe to omit quotation marks around attribute values in HTML if the attribute value only contains alphanumeric characters, hyphens and periods?I know that in HTML 4.01 and HTML 5 attribute values do not need quotation marks around them unless containing other than alphanumeric characters, hyphens and periods, but is it safe to do this?The reason is smaller unprocessed file size (because I have to escape the quotation marks in PHP), and also less bandwidth required to transfer the files (on FTP and via HTTP).
In my personal experience , “Omitting Quotation Marks” it is not always safe, especially when you deal with some JavaScript stuff. I suggest you keep it. Edited by uwspstar

Share this post


Link to post
Share on other sites

250 bytes means you have at least 125 attributes with alphanumeric characters... perhaps more in total.Sounds like a lot... are you using a lot of tables and presentational attributes? Or are you just using the "class" attribute extensively? Either way, you could try to slim up your code by various other means, like using descendant CSS selectors instad of many classes, or moving stuff into CSS instead of presentational attributes.As said, omitting quotes is possible, but it's not always safe. So, like W3C, I'd "recommend using quotation marks even when it is possible to eliminate them."

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...