WillMaster Possibillites Logo EzineSeek Award
JavaScript Syndication Feeds To JavaScript-Disabled Browsers
by
Mari Bontrager

Permission is granted to reprint this article in its entirety, provided no reprints are sent in conjunction with unsolicited bulk email, provided no fee or other value is exchanged, provided no changes are made to the article, and provided the author's name, signature lines, and copyright line are printed with the article; except you may change the article's title.

If you have syndicated content delivered with JavaScript, the increasing number of folks who turn their browser's JavaScript off can be a concern.

Syndicated content, in this article, means HTML content (text, images, forms, and so forth) delivered from a remote site and published on your page with JavaScript code similar to:

<script language="JavaScript" 
src="http://domain.com/file.js">
</script>

On our various sites, the percentage of visitors with non-JavaScript enabled browsers averages about 5%. This may be significant, depending on how important the content is to your site.

If you merely want to deliver a notice to non-JavaScript enabled browsers, the following on your page will do the job:

<noscript>
<h3>JavaScript required to view this content.</h3>
</noscript>

However, if you want to display the syndicated content to all browsers, this article will show you how.

Why They Turn It Off

During the last six months, every person who has told me s/he now surfs with JavaScript turned off is doing so because of the interruptive popups they were encountering. If you feel you must use popups on your site, "Pop-Under Windows — The Latest Pop-Window Trend" by Shelley Lowery presents methods to reduce visitor irritation. You'll find the article at http://www.web-source.net/popunder.htm

How To Deliver Syndicated Content To All Browsers

Instead of putting JavaScript code into your page, like the code presented above, use SSI (Server Side Includes). Your SSI page calls a script. The script retrieves the content and inserts it into your page.

The SSI tag is

<!--#exec cgi="/cgi-bin/JStoSSI.cgi"-->

Replace "/cgi-bin/JStoSSI.cgi" with the location and name of the script on your server. (The script is presented below.)

On many servers, pages with SSI need to have file names with the .shtml extension. Your server may be different. Contact your hosting company if in doubt.

For additional information about about SSI, see the "Server Side Includes" article linked from http://willmaster.com/possibilities/archives/

The Script

Here is the script your web page will call with the SSI tag:

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

Use a plain text word processor like NotePad or BBEdit to edit the first two lines of the script.

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

  • 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 <script... tag (if you were using the JavaScript method to insert the content). If you are syndicating these WillMaster Possibilities articles, the URL is http://willmaster.com/possibilities/c/wmp.js

Next, upload the script to your server. Upload it as ASCII/plain text to a directory that can run CGI scripts. In this article's examples, it is assumed you're uploading the script into the cgi-bin directory and that the file name of the script is JStoSSI.cgi, but you're not restricted to that.

NOTE: The above script 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/master/pit/

Review

A. If you were inserting syndicated content into your pages with JavaScript, the JavaScript would look something like this:

<script language="JavaScript" 
src="http://domain.com/file.js">
</script>

B. To use the SSI method instead:

  1. Replace the second line of the script with the URL in the scr="_______" attribute in the JavaScript.

  2. Replace the JavaScript itself with:

    <!--#exec cgi="/cgi-bin/JStoSSI.cgi"-->
    

    (Assuming the script is in the /cgi-bin/ directory and that the file name is JStoSSI.cgi)

Your SSI page will probably need the .shtml file name extension.

Your Own Syndicated Content

If you want to publish content that others are syndicating, see:

  1. http://willmaster.com/possibilities/syndication/

  2. http://www.web-source.net/syndicator.htm

The SSI method of inserting syndicated content presented in this article, in lieu of the JavaScript method of insertion, will work with many syndication content sources including both of those listed above.

If you want to syndicate your content to other web sites, see:

  1. "Syndicating Your Articles" (do-it-yourself information) linked from http://willmaster.com/possibilities/archives/

  2. Master Syndicator (product page) at http://willmaster.com/master/syndicator/

  3. Master Syndication Gateway I (product page) at http://willmaster.com/master/gateway1/

The SSI method presented in this article will work with the methods of creating syndicated content found at the three URLs, above.

If you are a webmaster syndicating content, you may wish to provide your remote syndication sites with the opportunity to use the SSI method. Simply send this article to them.

By: Will Bontrager

Copyright 2002 Bontrager Connection, LLC
http://willmaster.com/possibilities/
subscribe-possibilities@willmaster.com