Apple Engineer Talks About New 2016 Macbook Pro And iPhone 7!

Advertisements
Write better jQuery!

Write better jQuery!

jQuery is a great framework that make our life easer when it comes to start writing javascript or manipulate the DOM.

The only problem is that because jQuery make everything easer some developer forget to write good jQuery, that is following almost the same good practices that developers should use when writing JavaScript.

A very simple example of this is the following:

$(“document”).ready(function() {

});

This is the most popular way to start using jQuery. If you don’t care about populating with globals variables or the loading performance is not a worry for you, this kind of code works for you.

But when you are working with bigger applications you don’t want that your variables gets globals and obviously you want the best performance for you app.

The solution is follow the best practices. The example above can be written like this:

(function($, window, document) {

// now $ is locally scoped

$(function() {

// the DOM is ready

});

}(window.jQuery, window, document));

Do you wanna know even more best practices? Take a look to this article, is a must to read:

jQuery BEST PRACTICES

How To Add Embedds From SPOTIFY To WORDPRESS

You can find a great tutorial on how to add a song or an album from Spotify to WordPress. Check it out here: WordPress Support.

The trick for it to work (if it doesn’t) is however to add the song(or album) link FIRST.This means that it should be on top of your post. Otherwise you may experience problems such as the post only showing the link or an empty embedd.