IMO, you're doing the right thing to make sure you don't have encoding issues. A great way to improve performance is to place the elements in an Array
and only have the one call to append
with that array. The main performance implications with multiple append calls is that the DOM may have to recompute the layout of the screen after each time, and that will slow everything down.
var photos = [];
$.each(data.items, function(index, photo) {
var $imageSpan = $("<span></span>").addClass("image");
var $anchorTag = $("<a></a>").prop("href", photo.link);
$("<img/>").prop("src", photo.media.m.replace("_m", "_o")).appendTo($anchorTag);
$anchorTag.appendTo($imageSpan);
photos.push($imageSpan);
});
$photoDiv.append(photos);
I would also inline any HTML attributes which are not dynamic. For example, .addClass("image")
is not very beneficial; would be faster to put that attribute inline, with $('<span class="image"></span>')
.
Given the following example: setTimeout(function name(){console.log(1)}, 1000) (callback) Is name() (the callback) considered a function declaration or a named function expression? I know that ...
Given the following example: setTimeout(function name(){console.log(1)}, 1000) (callback) Is name() (the callback) considered a function declaration or a named function expression? I know that ...
I have a Backbone.Marionette item view. It renders a list of items. I want to listen for the scoll event everytime somebody scrolls the list. I assumed this would work: events: { 'scroll ul': '...
I have a Backbone.Marionette item view. It renders a list of items. I want to listen for the scoll event everytime somebody scrolls the list. I assumed this would work: events: { 'scroll ul': '...
I would like to use a javascript loop to create multiple HTML wrapper elements and insert JSON response API data into some of the elements (image, title, url, etc...). Is this something I need to go ...
I would like to use a javascript loop to create multiple HTML wrapper elements and insert JSON response API data into some of the elements (image, title, url, etc...). Is this something I need to go ...
I'm trying to read and add multiple files to an array. I've already found out that readAsArrayBuffer is a asynchronous function, so i need to wait for previous uploads to end. I tried to use callbacks ...
I'm trying to read and add multiple files to an array. I've already found out that readAsArrayBuffer is a asynchronous function, so i need to wait for previous uploads to end. I tried to use callbacks ...