Submit Your Article Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read


Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-24-2009, 12:07 PM
WebProWorld Veteran
 
Join Date: Jul 2003
Location: Spain
Posts: 364
computergenius RepRank 1
Default Why are Google Ads called in Javascript?

I am revisiting something that we started some time ago. We are about to start sharing some of our content, and this content will change automatically. For example, a list of events, which will update itself.

This will be included on other peoples sites. Those webmasters will need to "add a line of code", specifying what they want to see on their site.

I thought that the first place to look for an example would be Google Ads, where they put stuff onto other peoples sites.

But Google ads are called with Javascript. Obviously, the code must interrogate a database somewhere along the line, so the Javascript must call something else, as Javascript can't reach a database.

So why call the ads with Javascript, when you could call a PHP file? Seems like this would slow things down slightly, having to call a PHP / ASP file to get the data from a database. Why not call the PHP / ASP file direct?

I have a test working, calling a PHP file, with parameters, which will then format the results and add it to other peoples sites. But I can't help thinking that I could have missed something, if Google did it a different way!

Anyone know why Javascript was used to fetch Google Ads?
Reply With Quote
  #2 (permalink)  
Old 12-24-2009, 12:39 PM
chandrika's Avatar
WebProWorld Veteran
 
Join Date: Oct 2005
Location: Cambridge, UK
Posts: 489
chandrika RepRank 9chandrika RepRank 9chandrika RepRank 9chandrika RepRank 9chandrika RepRank 9chandrika RepRank 9chandrika RepRank 9chandrika RepRank 9chandrika RepRank 9chandrika RepRank 9
Default Re: Why are Google Ads called in Javascript?

The javascript in google ads uses inlined JSON to display content fetched from Google's servers. JSON is a lightweight computer data interchange format. It is a text-based, human-readable format for representing simple data structures and associative arrays (called objects).
JSON - Wikipedia, the free encyclopedia

Not all websites are php enabled, not all servers even host php, any website can insert javascript in html though and be sure for expected result, not every website can insert a line of php to the html code.

If you are sharing some changing content fom your website, have you thought of simply using rss, as that is widely used, easy to implement for anyone who wanted to place your shared content, so would be widely distributable...Google ads require some tracking and stuff, if you are sharing content that maybe all you need...
Reply With Quote
  #3 (permalink)  
Old 12-24-2009, 03:28 PM
WebProWorld Veteran
 
Join Date: Jul 2003
Location: Spain
Posts: 364
computergenius RepRank 1
Default Re: Why are Google Ads called in Javascript?

But surely JSON can't just be run from Javascript without an intermediary script? Can it?

I have tested the "include" line in HTML only files, that are not parsed for PHP, and it works fine. The code is called from my server, which can parse PHP, and so includes the expected output, even in HTML files.

I don't think that RSS is as simple as you imply, I want complete beginners to be able to insert a line of code, and pic up the information. RSS doesn't do that, it requires some kind of RSS reader on the receiving site, and that isn't always available. And I do want the feedback anyway.

I have used JSON, I will look at it again, but I need to pass some HTML to the receiving sites, so that there will be a default layout for those sites. The JSON that I have used in the past (on my own sites) was called from PHP (json_decode, etc)

But I will look at JSON again.
__________________
Pete Clark
Got any spare time? Anything you need? Barter in Spain at http://BarterWithBart.com
Reply With Quote
  #4 (permalink)  
Old 12-24-2009, 08:14 PM
Uncle Dog's Avatar
WebProWorld Veteran
 
Join Date: Apr 2008
Location: Scotland
Posts: 317
Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9
Default Re: Why are Google Ads called in Javascript?

Quote:
Originally Posted by computergenius View Post
I have tested the "include" line in HTML only files, that are not parsed for PHP, and it works fine. The code is called from my server, which can parse PHP, and so includes the expected output, even in HTML files.
The run of the mill PHP enabled server will parse HTML files for includes. If the first server doesn't do PHP then it just won't know what to do with an include statement.
__________________
There are 101 types of people in this world: those who understand binary, those who don't, Doc, kgun & deepsand
Reply With Quote
  #5 (permalink)  
Old 12-25-2009, 04:54 AM
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: Oct 2006
Posts: 1,079
innominds RepRank 5innominds RepRank 5innominds RepRank 5innominds RepRank 5innominds RepRank 5innominds RepRank 5
Default Re: Why are Google Ads called in Javascript?

I'm not a technical person but I feel that by using Javascript one can use limited bandwidth space.
Reply With Quote
  #6 (permalink)  
Old 12-25-2009, 05:34 AM
WebProWorld Veteran
 
Join Date: Jul 2003
Location: Spain
Posts: 364
computergenius RepRank 1
Default Re: Why are Google Ads called in Javascript?

Quote:
Originally Posted by Uncle Dog View Post
The run of the mill PHP enabled server will parse HTML files for includes. If the first server doesn't do PHP then it just won't know what to do with an include statement.
It's not a standard php include statement, but, if that were the case, then you would be correct. Although my server doesn't parse HTML for php includes. I know that it could be made to, but that is not what I need.

Have a look at
Untitled

This also works as
file://C:\develop... \temp.html (whatever the correct syntax is!)
from my local drive, by just clicking on it, no apache, nothing, just Windows Vista.

The "line to add" is
<script type="text/javascript" src="http://www.hotcosta.com/js/ip.php?a=ab&amp;b=cd"></script>

The php is on the "called" server, in this case, hotcosta.com

The only issue with this is, if I run it from my Windows PC local drive, I get an ActiveX warning with IE. But this does not appear when I call it from buydirectfromowners.com. And I can't figure out why this happens.

Perhaps there is something in the ActiveX warning that stopped Google from doing this with the ads? But it doesn't appear when I am calling the html file from a website.

If I could find a server with no PHP, perhaps I could try it. But I don't know any.
Reply With Quote
  #7 (permalink)  
Old 12-25-2009, 05:41 AM
WebProWorld Veteran
 
Join Date: Jul 2003
Location: Spain
Posts: 364
computergenius RepRank 1
Default Re: Why are Google Ads called in Javascript?

Quote:
Originally Posted by innominds View Post
I'm not a technical person but I feel that by using Javascript one can use limited bandwidth space.
If you use Javascript *in this case*, bandwidth will not be affected, the information will still have to passed to the browser somehow.

But Javascript can't read the database on the server, to pull out the info. It would have to call another file, in my case, a PHP file, and the PHP file would pull out the info, pass it to the browser, and the Javascript would then have to place the data into the page.

This is the sort of thing that Ajax does, but Ajax is great for changes once the page is loaded (user clicks, and part of the page changes), and in THAT way, the bandwidth is reduced, because instead of re-loading the entire page, only the changed section is loaded (or reloaded).

Using this system during a page download just seems to waste time, if the PHP file can be called directly.
Reply With Quote
  #8 (permalink)  
Old 12-25-2009, 06:26 PM
Uncle Dog's Avatar
WebProWorld Veteran
 
Join Date: Apr 2008
Location: Scotland
Posts: 317
Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9
Default Re: Why are Google Ads called in Javascript?

Quote:
Originally Posted by computergenius View Post
I have tested the "include" line in HTML only files, that are not parsed for PHP, and it works fine.
... and later ...

Quote:
Originally Posted by computergenius View Post
It's not a standard php include statement
Please make up your mind about what you are doing before asking a question about it.
__________________
There are 101 types of people in this world: those who understand binary, those who don't, Doc, kgun & deepsand
Reply With Quote
  #9 (permalink)  
Old 12-26-2009, 11:01 AM
WebProWorld Veteran
 
Join Date: Jul 2003
Location: Spain
Posts: 364
computergenius RepRank 1
Default Re: Why are Google Ads called in Javascript?

Quote:
Originally Posted by Uncle Dog View Post
Please make up your mind about what you are doing before asking a question about it.
Please make up your mind if you have anything useful to add before adding it
__________________
Pete Clark
Got any spare time? Anything you need? Barter in Spain at http://BarterWithBart.com
Reply With Quote
  #10 (permalink)  
Old 12-26-2009, 05:59 PM
chandrika's Avatar
WebProWorld Veteran
 
Join Date: Oct 2005
Location: Cambridge, UK
Posts: 489
chandrika RepRank 9chandrika RepRank 9chandrika RepRank 9chandrika RepRank 9chandrika RepRank 9chandrika RepRank 9chandrika RepRank 9chandrika RepRank 9chandrika RepRank 9chandrika RepRank 9
Default Re: Why are Google Ads called in Javascript?

Quote:
Originally Posted by computergenius View Post
I need to pass some HTML to the receiving sites, so that there will be a default layout for those sites.
Javascript can write some basic formatted html using document.write

Code:
<script type="text/javascript">
document.write("<h1>Hello World!</h1>");
</script>
This way external sites can call a javascript from your server. You can set your server to parse php in the .js file, same way as it now parses php in html file. In .htaccess in the AddType or Addhandler statement where it now has .htm .html , just add .js to the file types it will parse php in.

The .htaccessline differs somewhat across servers, on mine the line is

Code:
AddType application/x-httpd-php .htm .html
to which i can add the .js type

Code:
AddType application/x-httpd-php .htm .html .js

With php being parsed within a javascript on your server, you can then put dynamic php data in the javascript that is hosted on your server such as

Code:
document.write("<h1><?php echo $var ?></h1>");
That is my take on it....you may find the following link useful and better explained....
JavaScript Syndication: How to Easily Syndicate Your Web Content

Last edited by chandrika; 12-26-2009 at 06:09 PM.
Reply With Quote
  #11 (permalink)  
Old 12-26-2009, 07:17 PM
WebProWorld Veteran
 
Join Date: Jul 2003
Location: Spain
Posts: 364
computergenius RepRank 1
Default Re: Why are Google Ads called in Javascript?

Wow! A full example explaining how to parse PHP inside a Javascript file! I didn't know that you could do that!

And the page that you sent me to, appears to have a complete example to work from. Excellent.

Doing it this way, means that the IE ActiveX warning never appears under any circumstances.

Thanks for the input, it's appreciated.
Reply With Quote
  #12 (permalink)  
Old 12-26-2009, 07:27 PM
Uncle Dog's Avatar
WebProWorld Veteran
 
Join Date: Apr 2008
Location: Scotland
Posts: 317
Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9
Default Re: Why are Google Ads called in Javascript?

Quote:
Originally Posted by computergenius View Post
Please make up your mind if you have anything useful to add before adding it
It's useful to point out that you start by claiming that you 'have tested the "include" line in HTML only files, that are not parsed for PHP, and it works fine' and then later retract that by saying "It's not a standard php include statement"

You also started by querying "why call the ads with Javascript, when you could call a PHP file?" and then later, when explaining a solution, reveal that you've seen it done with JavaScript: The "line to add" is
<script type="text/javascript" src="http://www.hotcosta.com/js/ip.php?a=ab&amp;b=cd"></script>

The php is on the "called" server, in this case, hotcosta.com


What I was adding, usefully, to the conversation is that we'll all find it rather difficult to score (answer your query) when you keep moving the goalposts (changing your question).
__________________
There are 101 types of people in this world: those who understand binary, those who don't, Doc, kgun & deepsand
Reply With Quote
  #13 (permalink)  
Old 12-27-2009, 04:35 AM
WebProWorld Veteran
 
Join Date: Jul 2003
Location: Spain
Posts: 364
computergenius RepRank 1
Default Re: Why are Google Ads called in Javascript?

The question never changed. "Why are Google Ads called in Javascript" was the original question.

I was saying that, as Javascript can't access a database, it appears that Javascript has to call something else, wasting more time at a critical point. Google's Ad code calls Javascript, my code was calling PHP, eliminating one step on the ad server. I couldn't understand why Google were calling a .js file.

chandrika helpfully pointed out that Javascript could be parsed for PHP, their implication being that you can call .js, and parse it for PHP, thus avoiding the need for calling a second file on the server. The question is answered. "because Javascript can be parsed for PHP"
__________________
Pete Clark
Got any spare time? Anything you need? Barter in Spain at http://BarterWithBart.com
Reply With Quote
  #14 (permalink)  
Old 12-30-2009, 05:02 PM
WebProWorld New Member
 
Join Date: Sep 2009
Location: Dorset, UK
Posts: 6
iguru RepRank 0
Default Re: Why are Google Ads called in Javascript?

i have just written an in depth guide on how you can do what you want and why google do it that way. and how you can use the same tricks as they do but this stupid site does not let me post it !

Well done
Reply With Quote
  #15 (permalink)  
Old 12-30-2009, 05:09 PM
WebProWorld New Member
 
Join Date: Sep 2009
Location: Dorset, UK
Posts: 6
iguru RepRank 0
Default Re: Why are Google Ads called in Javascript?

btw way simple answer: server side included do not (in basic format) send client info back to google. Javascript includes (as that is essentially what they are) can and do send everything about the users browser and computer back to the src file (php asp pl) that dumps that info into googles fat server farm. And decent browser supports a single line of javascript. a server side script would have to be available in many, php, perl, asp(vbscript) aspx(C#. vb.net, Jscript), ruby, python the list goes on and on..

That my friend is THE ANSWER
Reply With Quote
  #16 (permalink)  
Old 12-30-2009, 06:41 PM
WebProWorld New Member
 
Join Date: Sep 2009
Posts: 3
regedanzter RepRank 0
Default Re: Why are Google Ads called in Javascript?

You could use PHP even if the site that is hosting your content doesn't have PHP i.e. just have them call it remotely by an image file. For a good example see Free Trust Seal d com
Reply With Quote
  #17 (permalink)  
Old 12-30-2009, 10:32 PM
mjtaylor's Avatar
Moderator
WebProWorld Moderator
 
Join Date: Dec 2003
Location: Key West / Asheville, NC
Posts: 2,767
mjtaylor RepRank 9mjtaylor RepRank 9mjtaylor RepRank 9mjtaylor RepRank 9mjtaylor RepRank 9mjtaylor RepRank 9mjtaylor RepRank 9mjtaylor RepRank 9mjtaylor RepRank 9mjtaylor RepRank 9mjtaylor RepRank 9
Default Re: Why are Google Ads called in Javascript?

Quote:
Originally Posted by iguru View Post
i have just written an in depth guide on how you can do what you want and why google do it that way. and how you can use the same tricks as they do but this stupid site does not let me post it !

Well done
If you really have something of value to share, you can type domainDOTcom/file ...
__________________
M.-J. Taylor
SEO Web Design by Cyber Key Search Smart DesignŽ SEO Copywriter & Traveling Vacation Gypsy
Reply With Quote
  #18 (permalink)  
Old 01-01-2010, 09:37 AM
Uncle Dog's Avatar
WebProWorld Veteran
 
Join Date: Apr 2008
Location: Scotland
Posts: 317
Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9Uncle Dog RepRank 9
Default Re: Why are Google Ads called in Javascript?

Quote:
Originally Posted by mjtaylor View Post
... you can type domainDOTcom/file ...
That's maybe a bit too technical for iguru.
__________________
There are 101 types of people in this world: those who understand binary, those who don't, Doc, kgun & deepsand
Reply With Quote
  #19 (permalink)  
Old 01-01-2010, 08:44 PM
VideoWhisper.com's Avatar
WebProWorld New Member
 
Join Date: Dec 2008
Posts: 21
VideoWhisper.com RepRank 1
Default Re: Why are Google Ads called in Javascript?

1. JavaScript dynamic content can be added to any type of site, including static html sites.
Inclusion is same for php, asp, jsp, plain html sites.

2. Client server side code would have to query the google servers to get data (ads to show). That means some delay before receiving response and displaying the final content. JavaScript loads after page rendering without causing delays.

3. Client server side code would not allow controlling what type of ads show on different pages depending on context. People could get some ads and display these on irrelevant pages, newsletters. Also counting impression would not be possible. Ads could be fetched once and displayed multiple times.
__________________
VideoWhisper Flash Video Streaming features for websites: Video Conference, Video Recorder, 2 Way Video Chat, Live Streaming, Video Consultation. Free versions to download.
Reply With Quote
  #20 (permalink)  
Old 01-02-2010, 12:18 PM
deepsand's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2004
Location: Philadelphia, PA
Posts: 4,197
deepsand RepRank 10deepsand RepRank 10deepsand RepRank 10deepsand RepRank 10deepsand RepRank 10deepsand RepRank 10deepsand RepRank 10deepsand RepRank 10deepsand RepRank 10deepsand RepRank 10deepsand RepRank 10
Default Re: Why are Google Ads called in Javascript?

Quote:
Originally Posted by VideoWhisper.com View Post
2. Client server side code would have to query the google servers to get data (ads to show). That means some delay before receiving response and displaying the final content. JavaScript loads after page rendering without causing delays.

3. Client server side code would not allow controlling what type of ads show on different pages depending on context. People could get some ads and display these on irrelevant pages, newsletters. Also counting impression would not be possible. Ads could be fetched once and displayed multiple times.
I think you mean to say server-side, as there is no such thing as client-server-side.

Code is executed either on the server or the client, but not both.

JScript is client-side.
Reply With Quote
  #21 (permalink)  
Old 01-23-2010, 01:35 AM
WebProWorld New Member
 
Join Date: Jan 2010
Posts: 11
krisov RepRank 0
Default Re: Why are Google Ads called in Javascript?

Thanks for sharing.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help! I think I'm under attack by a bot called startdedicated wilderness Internet Security Discussion Forum 16 10-03-2008 08:04 PM
A network called 'Internet' whipnet The Castle Breakroom (General: Any Topic) 1 07-15-2006 03:18 PM
They have to be called something coder The Castle Breakroom (General: Any Topic) 12 06-28-2005 04:48 PM
CRM program called Maximizer tntpics Database Discussion Forum 0 11-18-2004 12:56 PM
What's the called? wbsweb Web Programming Discussion Forum 3 01-28-2004 11:55 AM


All times are GMT -4. The time now is 02:51 PM.



Search Engine Optimization by vBSEO 3.3.0