Skip to content

Performance in ANY_INNERHTML_BUGGY feature tests #164

Open
@jwestbrook

Description

@jwestbrook

previous lighthouse ticket #1487
by Victor


Currently Prototype detects 3 innerHTML flaws: SELECT_ELEMENT_INNERHTML_BUGGY, TABLE_ELEMENT_INNERHTML_BUGGY, LINK_ELEMENT_INNERHTML_BUGGY during page load. This requires HTML parsing in browser and slows page loading.

Check for TABLE_ELEMENT_INNERHTML_BUGGY may be skipped when SELECT_ELEMENT_INNERHTML_BUGGY is true, because they are used only in boolean expression.

Furthermore, LINK_ELEMENT_INNERHTML_BUGGY may be skipped in the same way, until it is actually needed in update() when content contains tag.

These checks may be refactored to memoizing functions, allowing to invoke them directly where they are needed:

var SELECT_ELEMENT_INNERHTML_BUGGY = function() {
  var el = document.createElement("select"), isBuggy = true;
  el.innerHTML = "<option value=\"test\">test</option>";
  if (el.options && el.options[0]) {
    isBuggy = el.options[0].nodeName.toUpperCase() !== "OPTION";
  }
  el = null;
  SELECT_ELEMENT_INNERHTML_BUGGY = isBuggy ? function() {return true} : function() {return false};
  return isBuggy;
};

// skipped

var ANY_INNERHTML_BUGGY = SELECT_ELEMENT_INNERHTML_BUGGY() ||
  TABLE_ELEMENT_INNERHTML_BUGGY() || LINK_ELEMENT_INNERHTML_BUGGY();

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions