Helping ordinary people create extraordinary websites!
GET OUR NEWSLETTER
Your Email:
 

Search Engine Spider-Friendly JavaScript Content

By Will Bontrager
2005-09-24


The CGI Program

Here is the CGI program that will fetch the syndicated content and send it to your web page:

#!/usr/bin/perl

my $JavaScriptURL = 'http://example.com/file.js';
use strict;
use LWP::Simple;
my $content = get $JavaScriptURL;
$content =~ s/^\s*<!--//s;
$content =~ s!(?://)?\s*-->\s*$!!s;
my @content = split /[\r\n]+/,$content;
for(@content)
{
unless(/^document/) { $_ = ''; next; }
$_ =~ s/^document\.writeln\(\'//;
$_ =~ s/'\)\;$//;
$_ =~ s/' ?\+ ?'//g;
$_ =~ s/\\'/'/g;
$_ =~ s/\\\\/\\/g;
}
$content = join "\n",@content;
print "Content-type: text/html\n\n$content";
# end of script

Edit and save the above program using a plain text word processor like NotePad or TextWrangler.

  1. The first line must point to the location of Perl on your server.

  2. On the second line, replace the URL between the apostrophes with the URL of the syndicated content. This would be the URL found in the src="_________" attribute of the syndication <script...> tag. (To syndicate WillMaster Possibilities articles, use the http://willmaster.com/possibilities/c/wmp.js URL.)

Upload the program to your server as ASCII/plain text, to a directory that can run CGI scripts. Give it 755 permissions.

It requires the Perl module LWP::Simple. If you are unsure whether or not your server has the module installed, ask your hosting company or use Master Pre-Installation Tester from http://willmaster.com/mpits



Tutorial Pages:
» Search Engine Spider-Friendly JavaScript Content
» The CGI Program
» The SSI Tag


Copyright 2004 Bontrager Connection, LLC


 | Bookmark
Related Tutorials:
» JavaScript Debugging Techniques with Firebug
» Striped Tables Using JavaScript
» Opening PDFs in a New Window with JavaScript
» Essential Javascript -- A Javascript Tutorial
» Submit Forms Conditionally using JavaScript
» How to Setup a Randomising Function

Advertise with Us!


Tutorials Scripts Web Hosting Developer Manuals
Resources