Chapter 11. Adding JavaScript and CSS to Themes

IN THIS CHAPTER

  • Examining the jQuery and Prototype frameworks

  • Leveraging WordPress' JavaScript libraries

  • Examining WordPress plugins that use JavaScript effects

  • Looking at theme styles

As the Internet evolves and more emphasis is placed on interactivity and user experience, the need for JavaScript increases. Using JavaScript has evolved from being painfully difficult, requiring browser detection and massive duplication of code to achieve a consistent user experience, to relatively simple, with implementations that work across all browsers. What once took developers 50 lines of code or more to achieve can now be done in just a few lines and is more reliable.

JavaScript is a client-side language, meaning it is not executed on a server as PHP is. Instead, it relies on Web browsers to interpret it and handle it accordingly. The benefit is a simplistic concept of distributed computing, where the weight of processing and execution is not handled in a central spot, but distributed across all the computers accessing the Web page or Web application. In recent years, JavaScript has also been a cornerstone of highly interactive Web applications.

With the advent of Ajax (Asynchronous JavaScript and XML), Web applications gained the capability to use a hybrid model, where most of the user experience happens on the front end while background communication with servers handles most of the processing. This hybrid model provides a much more robust way to ...

Get WordPress® Bible now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.