New filter idea: Remove empty tags #246

GoogleCodeExporter opened this Issue Apr 6, 2015 · 9 comments


None yet
1 participant
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

Original issue reported on by on 20 Mar 2011 at 3:40

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?

Original article

And follow up - the author succeeded in getting changes made to the html5 spec 
and a check added to YSLOW

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 on 20 Jan 2012 at 1:54

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 on 20 Jan 2012 at 2:21

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

<input type="image">

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 on 20 Jan 2012 at 4:01

src is a REQUIRED attribute for img at least 
I expect this is the case for most/all of the others as well.

Original comment by on 20 Jan 2012 at 4:14

Original comment by on 24 May 2012 at 7:26

  • Changed state: Accepted

Original comment by on 28 Nov 2012 at 7:11

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

Original comment by on 20 Jun 2014 at 3:41

In removing empty tags we should at least leave ones that have ids.  Otherwise 
we would break code like 
that defines <div id=foo></div> and then uses JS to populate it.

Original comment by on 4 Aug 2014 at 5:55

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 on 6 Aug 2014 at 7:36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment