SCEditor
SCEditor copied to clipboard
Implement style cache
Motivation
Nodes are frequently created, updated, and destroyed, but would always use the same styles. Repeated calls to getComputedStyle() for the same or similar elements were causing noticeable performance degradation because the browser was recalculating the same or similar styles.
Summary of Changes
-
Signature-based caching
- Computed styles are cached using a signature derived from an element’s
tagName,id,class, andstyleattributes. - Elements with the same signature reuse the cached style snapshot.
- Computed styles are cached using a signature derived from an element’s
-
API
dom.cachedCss(node, "prop")→ returns a single computed property.dom.cachedCss(node, ["prop"])→ returns one or more computed properties as object.dom.cachedCss(node, "prop", "val")→ sets inline style