prepend new elements instead of replacing HTML on AJAX update (#9) (#12)

Replacing the body by prepending HTML results in the full content
being re-rendered. This can be a performance issue, but is definitely
annoying when embedding media in ticks.
This commit is contained in:
Stefan Kalscheuer 2020-05-01 14:52:25 +02:00
parent 04131a1d99
commit d75b790ccf
2 changed files with 10 additions and 2 deletions

View File

@ -85,6 +85,7 @@ caching time of 12 hours obviously makes no sense.
* Use GMT for automatic updates * Use GMT for automatic updates
* Gutenberg Block available * Gutenberg Block available
* Ticks exposed through REST API * Ticks exposed through REST API
* Changed AJAX update logic for embedded media compatibility
### 1.0.0 - 2018-11-02 ### 1.0.0 - 2018-11-02

View File

@ -164,8 +164,15 @@
* @return {void} * @return {void}
*/ */
var updateHTML = function( t, u ) { var updateHTML = function( t, u ) {
// Prepend HTML of new ticks. // Parse new DOM-part.
t.e.innerHTML = u.h + t.e.innerHTML; var n = document.createElement( 'ul' );
n.innerHTML = u.h;
// Prepend new ticks to container.
while ( n.hasChildNodes() ) {
t.e.prepend( n.lastChild );
}
t.e.parentNode.setAttribute( 'data-sclt-last', u.t ); t.e.parentNode.setAttribute( 'data-sclt-last', u.t );
// Remove tail, if limit is set. // Remove tail, if limit is set.