HTML and CSS Reference
In-Depth Information
Listing 3-8. A Basic JSON Structure
"people": [
{"name": "John",
"age":"28",
"title":"Developer"
},
{"name": "Alison",
"age":"26",
"title":"Teacher"
}]
In web advertising, developers are always working with external APIs to bring more relevance to ad units.
A typical request is to pull an advertiser's recent news via an RSS feed into the ad unit. A good tool to use for this
purpose in JSON format is one from the founder of jQuery, John Resig: RSS2JSON ( ejohn.org/projects/rss2json ) .
Note
we'll cover JsOn in more depth using api's in chapter 11.
JavaScript Libraries
Because writing native JavaScript can be cumbersome at times, many talented developers have created libraries
and abstractions for working with and writing native JavaScript. Most of the time using a JavaScript library in the ad
environment means you're adding additional code bloat to your ad. Keep in mind that you can do everything these
libraries do in native JavaScript, so always weigh the pros and cons of relying on a library to get the job done. That
said, probably the most popular library is jQuery.
jQuery
jQuery is huge among the developer community base, and it has a very clean and simple coding language. In fact, I've
seen firsthand many Actionscript developers head toward working with jQuery when moving from Flash to JavaScript
development. That approach has some pros and cons, though. On the one hand, jQuery has a very simple syntax, one
that AS3 developers find themselves at home in. On the other hand, jQuery has its downsides in the advertising world
because it will increase overall k-weight and may be unnecessary for simple ad creations. If you notice that you're
using jQuery to simply animate a few items on-screen and to easily reference DOM nodes, you really should stop
using it. If you absolutely must lean on jQuery for cross-browser compatibility or something similar, the best thing ad
servers can do is provide an option to use it or not, depending upon whether the publisher's page has incorporated it.
Since jQuery is so popular—I mean really, really popular—there is a good chance that you, as a developer, won't have
to include it in a redundant fashion for your ad content. Simply leverage jQuery if the publisher already has it loaded.
Do a quick conditional check, something like the one in Listing 3-9.
Listing 3-9. A jQuery Conditional Check
<script>
(function(window){
var latestVersion = "1.8.2";//update to jQuery's latest version
var libraries = {
pubjQuery: window.jQuery || window.$,
 
 
Search WWH ::




Custom Search