Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

New filter idea: Remove empty tags #246

Open
GoogleCodeExporter opened this issue Apr 6, 2015 · 9 comments
Open

New filter idea: Remove empty tags #246

GoogleCodeExporter opened this issue Apr 6, 2015 · 9 comments

Comments

@GoogleCodeExporter
Copy link

This cannot be done in 'safe' mode because it could alter the structure of the 
DOM and break JS.  But it's not a bad idea as an option.  See

http://calendar.perfplanet.com/2010/mod_pagespeed-performance-review/


Original issue reported on code.google.com by jmara...@google.com on 20 Mar 2011 at 3:40

@GoogleCodeExporter
Copy link
Author

Could we not rewrite some of these to serve empty files so as to not change the 
DOM? e.g. the image tag serve an empty or very small image?

FYI 
Original article 
http://www.nczonline.net/blog/2009/11/30/empty-image-src-can-destroy-your-site/

And follow up - the author succeeded in getting changes made to the html5 spec 
and a check added to YSLOW
http://www.nczonline.net/blog/2010/03/16/empty-string-urls-in-html-a-followup/

With most browsers another page request is made to fill in the data. This can 
either be a request to the directory or a reference to the page that is hosting 
the offending tag.

For reference, the following are examples of problematic tags;

<img src="">
<input type="image" src="">
<script src="">
<link rel="stylesheet" href="">
<embed src="">
<object data="">
<iframe src="">
<video src="">
<video poster="">
<audio src="">
<command icon="">
<html manifest="">
<source src="">

this can also happen in Javascript;

var img = new Image();
img.src = "";



Original comment by the.andr...@gmail.com on 20 Jan 2012 at 1:54

@GoogleCodeExporter
Copy link
Author

The server is asked for the directory (IE) or base URL (all others) so 
detecting that it was an empty URI on the server side is not trivial - it 
*looks* like a valid request in many ways.

I think the original suggestion of filtering these out is more viable (although 
the relationship of this problem to -pagespeed- is debatable IMO :).

Original comment by matterb...@google.com on 20 Jan 2012 at 2:21

@GoogleCodeExporter
Copy link
Author

Could we improve this by removing only the offending attribute (not the whole 
element). So we would have:

<img>
<input type="image">
<script>
...

The only question might be if anyone would ever actually mean for the empty 
string to be interpreted like the spec. Given the inconsistent browser 
behavior, I'm guessing not.

Original comment by sligocki@google.com on 20 Jan 2012 at 4:01

@GoogleCodeExporter
Copy link
Author

src is a REQUIRED attribute for img at least 
(http://www.w3.org/TR/html401/struct/objects.html#h-13.2)
I expect this is the case for most/all of the others as well.

Original comment by matterb...@google.com on 20 Jan 2012 at 4:14

@GoogleCodeExporter
Copy link
Author

Original comment by jmara...@google.com on 24 May 2012 at 7:26

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

Original comment by jmara...@google.com on 28 Nov 2012 at 7:11

@GoogleCodeExporter
Copy link
Author

Issue 92 could probably be handled by the same new filter, if we did this.

Original comment by jefftk@google.com on 20 Jun 2014 at 3:41

@GoogleCodeExporter
Copy link
Author

In removing empty tags we should at least leave ones that have ids.  Otherwise 
we would break code like 
https://developers.google.com/maps/documentation/javascript/examples/map-simple 
that defines <div id=foo></div> and then uses JS to populate it.

Original comment by jefftk@google.com on 4 Aug 2014 at 5:55

@GoogleCodeExporter
Copy link
Author

This needs to be optional as javascript might also populate empty tags using 
classes or just jQuery links to a specific tag element...

Original comment by rwap.services on 6 Aug 2014 at 7:36

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant