Forum Moderators: open

Message Too Old, No Replies

Place RSS JS code in external JS file & Call it

         

jcdb

2:34 am on Sep 8, 2004 (gmt 0)

10+ Year Member



Hello,
I have a php parser generated JS code for an RSS feed for my webpage and I would like to place this code in an external JS file and call it instead of having the code in my html document. I tried it but did not work. Can anyone help me? Here's the JS code generated by the parser.

<script language="JavaScript" src="http://www.site.com/php/phpfeed/feed123js.php?src=http%3A%2F%2Fwww.feedURLsite.com%2Fabout%2Frss%2FfeedURLsite.rss&chan=n&num=2&desc=0&date=y&targ=y" type="text/javascript"></script>

<noscript>
<a href="http://www.site.com/php/phpfeed/feed123js.php?src=http%3A%2F%2Fwww.feedURLSite.com%2Fabout%2Frss%2Ffeedurlsite.rss&chan=n&num=2&desc=0&date=y&targ=y&html=y">View RSS feed</a>
</noscript>

Again , this code is placed directly in my html but I would like to save this code in a .js file and call it externally for faster page load.

Thanks

StupidScript

8:45 pm on Sep 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Using the <script src= ... method will not improve the page loading speed, as it makes an additional request to the server for the .JS file, and includes it in its entirety. It's actually faster, performance-wise, to put the JS code right in your page.

Since you're using PHP, why not use PHP includes?

<?php

include "http://www.site.com/php/phpfeed/feed123js.php?src=http%3A%2F%2Fwww.feedURLsite.com%2Fabout%2Frss%2FfeedURLsite.rss&chan=n&num=2&desc=0&date=y&targ=y";

?>

No Javascript required! :)

I did notice that the src= URI you are trying to include (just the cleaned up query string part) returns a "The page cannot be displayed", so maybe that has something to do with the success of this effort?

jcdb

2:56 am on Sep 9, 2004 (gmt 0)

10+ Year Member



The php include did not work

StupidScript

6:41 pm on Sep 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What errors are you receiving?

It looks like the problem may be in the syntax of the query string you are sending over to feedURLsite.com. Due to your prior use of the "?" query separator, you are precluded from using it in the src= value:

ttp://www.feedURLsite.com/about/rss/feedURLsite.rss&chan=n&num=2&desc=0&date=y&targ=y

should probably be:

ttp://www.feedURLsite.com/about/rss/feedURLsite.rss?chan=n&num=2&desc=0&date=y&targ=y

in order to work. Note the replacement of the "&" with a "?" following "feedURLsite.rss".

In addition, the your query string is being acted on by feed123js.php, like this:

ttp://www.site.com/php/phpfeed/feed123js.php
?src=http://www.feedURLsite.com/about/rss/feedURLsite.rss
&chan=n
&num=2
&desc=0
&date=y
&targ=y

So all you are sending to feedURLsite is its own page address, but none of the other parameters are making it.

How about using the proper query syntax to get the feed directly using a PHP include:
<?php
include "http://www.feedURLsite.com/about/rss/feedURLsite.rss?chan=n&num=2&desc=0&date=y&targ=y";
?>

Do you really need to use the feed123js.php file?

StupidScript

7:00 pm on Sep 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you using JS to get the "n" variable for which channel to display?