jQuery with PHP

Hi, mina! As you might have guess this is yet another review af a Packt Publishing book named “jQuery 1.3 with PHP” by Kae Verens. As the title suggests, the book discusses mostly jQuery and it’s usages with PHP. Even there is PHP in the name, you can use any of the server side web programming language you want. What really matters is what you can do with jQuery, and what jQuery plugins can do the “thing” you want to do. There is nothing in this book which you can’t find on the web. But the real thing is that it puts together most of the things you will need and creates a great cookbook for back-end developers who want to do some “web 2.0 stuff” without knowing a lot of Javascript and cross browser compatibility.

In the first chapter book describes what are AJAX, JSON, jQuery and Javascript. It’s a simple chapter and you might pass if you have already used jQuery or Prototype or MooTools or Dojo or Yahoo UI or any Javascript library. The book also tells you “why” you should choose jQuery which I agree with him. It’s not very clean, it’s generally “quick and dirty” but you just want to get the thing done with front-end development and you want something that helps you overcome this “burden” of yours and jQuery generally helps you achieve it. It does not stand on your way.

The second chapter is where you will see some demonstrations. It will give you a quick overview on the matter with jQuery-PHP-HTML integration, how the data is handled, how you can create inline edit buttons, dinamic select boxes, etc and will get you in to the action as fast as possible. However this is just a quick way to demonstrate you that you can do a lot of things with jQuery without even knowing anything and just copy-pasting would be enough. Later it code will be explained and you will get a detailed idea on how everything fits together. The later chapters will discuss more specific ways like file handling, data grids, etc thoroughly.

From chapter 3 to 9 there are detailed descriptions and how-to’s for things like tabbed pages, data grid views (data tables), drag-n-drop’s, image editing tools etc. These chapters are the heart of the book and they contain a lot of recipes. The best part of these chapters is that it does give you both the plugin and how to use it. So you know what to download and add it as library for the specific task you need to do and you also know how to use it.

The last chapter is about optimization. How to optimize jQuery, loading of js scripts. It is always important that you have a “fast” web page. A page which loads instantly and show the user most of the things they want. But as you may guess it’s generally not possible. There some tips you can use in the chapter, however I do not agree with all. Some of them are not even optimization but tricks. However writing plugin part was cool. I wish the author had done everything he had done with creating his own plugins and by this way showing the best way. By this way he could have better showed that optimization is not done after the code has written but during the writing process. You cannot optimize anything after you have done it. If you do, things you can do will be very limited and it will only help you some milliseconds instead of hundreds of milliseconds. You can’t increase the performance by increasing the hardware of the server you are using (opposing to the general view with developers) but actually improving your own code. Especially with javascript you should be even more careful, because it’s not ran on the server but on the client, so time/process/memory consuming scripts may even the crash the browser!

The author also mentions to use Google CDN, to load javascripts instead of keeping in your own server. It’s a good way of course, because the script will already be cached etc however don’t forget that you will be dependent to Google’s service. I know that probably you can never manage your server better then Google however I prefer to be not dependent to Google if I’m on a production server. This may even be problematic if Google’s IP’s where blocked and yours were not (theoretical of course, it does not seem very possible. However, YouTube gets banned 4-5 times in a year for months in my country by the court for funny reasons. So don’t think it cannot happen!). You should have a backup plan in case that user cannot reach Google.

He also mentioned “Caching jQuery Objects”, while his point is valid and something that a good developer must do, this is not called caching, it’s called “variable assignment”. Instead of calling one function 10 times you call it one time and you assign it to a variable and later use it, you cannot call it actual caching but “best practice”.

If you do not look the last chapter as optimization but “best practices”, it really is a good chapter (at the end of the chapter even author admits that “it’s more about making your code more efficient then making client side faster”). It describes the common errors done by programmers (especially new ones), errors done because of insufficient javascript knowledge, etc. This was the chapter I cared most and I learned a thing or two but I won’t be able to say It was great.

Finally as last thoughts, think this book as a book which you will keep in your library for a year or two. It does not contain anything which cannot be found on the internet however it saves you time from searching it and puts most of the things you will need when creating a “RIA” and also contains how-to’s. It’s not a book you should start reading from top to bottom like the previous books I reviewed (Magento and Zend Framework) because it does not contain a whole application, it only contains recipes and it’s a good cookbook while some of the code examples would have been better. Many of the examples are kept simple for the sake of simplicity and easy understanding as the primary audience is the back-end developers who only thinks to get it done on the front-end.

If you know nothing about Javascript and jQuery (or if you only copy-pasted from somewhere else without knowing what you have done:) it might be a good start, if you are an expert or used jQuery before, there are still things which this book can give to you however very limited.