Page MenuHomePhabricator

Remove the name attribute from header <a> tags
Closed, ResolvedPublic

Description

Removes the name attribute from the <a> of headers, the editing <textarea>, and Monobook's <a id="top">

MediaWiki currently emits both name and id attributes for <a> tags used for headers. I believe the name should be removed, because it measurably increases the size of each article with headers for no good reason.

The name attribute used in this fashion appears to only be required for compatibility with Netscape 4, which does not recognize the id attribute for the purpose of jumping to a point in a page (based on the portion of the URL following the # symbol).

Netscape 4 is no longer in common or uncommon usage. It was removed from http://www.w3schools.com/browsers/browsers_stats.asp at the start of 2005 (when IE5 still had 10% of the market). All modern browsers recognize the id attribute for this function, as per the HTML 4.01 standard:
http://www.w3.org/TR/REC-html40/struct/links.html#anchors-with-id

Removing the name attribute is easy. The savings are small but measurable - even for larger articles with high proportions of body text to headings - and I feel they outweigh the minor loss of functionality on an obsolete browser.

For example, the current featured article on the English Wikipedia, http://en.wikipedia.org/wiki/Kevin_Pietersen has the following size (gzip in parentheses):

With name attribute: 251,917 (48,002) bytes
Without name attribute: 251,061 (47,863) bytes
Reduction: 856 [0.3%] (139 [0.3%]) bytes

The relative savings are increased for languages which have long names/ids due to restrictions on the characters present in ids, and for shorter pages with several headings.

The name attribute on the editing textarea (<textarea name="wpTextbox1" id="wpTextbox1">) and Monobook's top anchor (<a name="top" id="top">) might also be removed, although the savings here will obviously be limited.


Version: unspecified
Severity: enhancement
URL: http://en.wikipedia.org/wiki/Kevin_Pietersen

Attached:

Details

Reference
bz19576

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 10:41 PM
bzimport added a project: MediaWiki-Parser.
bzimport set Reference to bz19576.
bzimport added a subscriber: Unknown Object (MLST).

It might also be possible to place the id completely inside the <hX> tag, removing the <a id=\"$anchor\"></a> line completely for even more savings. However, I am unsure of the implications of this; in particular, whether callers of makeHeadline (only Parser::formatHeadings()?) may have added an id to $attribs in some circumstances.

Created attachment 6306
Removes the <a> entirely, moving the id to the header tag

Demonstrates the alternative approach mentioned in Comment #1.

Attached:

Implemented by rememberthedot in r52963.

Reimplemented in r53577.