View Full Version : Server-side Javascript?
Dylan Leblanc
12-22-2002, 04:51 AM
There is a large part of my website which is output with Javascript, but I still want non-Javascript users to have access. I have determined that it is too much of a hassle to maintain both a Javascript and an HTML output system.
All the Javascript does is issue a bunch of document.write() functions on a set of data, run through a few loops. So it would be possibe to "render" the Javascript document on my server and send it out for users who can only view HTML.
So what do I need to run server-side Javascript, and run documents through there after being created with PHP? I know this is sort of unconventional, but I want to do it. My server is Linux, Apache, PHP, etc. setup with Plesk.
Mhtml
12-22-2002, 08:35 AM
Why not just use PHP?
Dylan Leblanc
12-22-2002, 10:32 AM
Because I already have an extensive Javascript output system it is a hassle to have another one in PHP to create output for HTML-only users.
brothercake
12-22-2002, 12:46 PM
Not to contradict you - but it needn't be so much hassle. My experience is that 80% of JS-PHP conversion is changing var to $, document.write() to echo(), and other such simple semantics.
The other 20% tends to be stuff that can't be done on the server at all .... :)
AFAIK server-side javascript can only run on netscape servers. I think it's generally considered to be obsolete technology now that we have things like PHP, ASP and JSP.
How big is the script? Maybe we could do the conversion for you ... if it's not, like, ridiculous :)
Mhtml
12-22-2002, 02:19 PM
... if it's not, like, ridiculous :)
lol :)
Because I already have an extensive Javascript output system it is a hassle to have another one in PHP to create output for HTML-only users
If you think it is a hassel to put in the effort then why bother with html only users? Catering for different types of users isn't easy and some times you will code a large project and then find out that it won't work for this, this and this browser. Then you aarrrggghhh and throw your computer out the window. ;) You've just got to hope your computer has a rubber case and you can start again to make it better.
Dylan Leblanc
12-22-2002, 11:56 PM
Well like brothercake was saying, since Javascript and PHP are similar in syntax, I have been thinking of writing a conversion program to take the JS script, whenever changes are made to it, and translating it to PHP. Then run the output for HTML-only users through this PHP script. Sounds strange but I don't think it would be too much work. Easier then constantly maintaining two output systems.
I have heard of something called mod_js for Apache, but it seems very hard to find.
krycek
12-23-2002, 12:09 AM
brothercake is correct, server-side JS is considered obselete these days. I also would agree that only Netscape servers would run it... I remember having horrific problems trying to get it to work properly for a client using Netscape Enterprise Server 2 years ago... I convinced them to use ASP instead (yeah I know, but PHP was not as popular back then, plus I didn't convert from ASP to PHP till last January lol :p)
I would suggest that you convert your scripts to PHP, or else don't change anything, because even if you find a stable Apache module for it, it will be nowhere near the performance and features of PHP.
Trust me, I'm a not a doctor... I'm a programmer ;)
::] krycek [::
Dylan Leblanc
12-23-2002, 07:52 AM
Thanks for your suggestions guys!
This is the Javascript which I had wanted to be able to run on the server: http://skyscraperpage.com/diagrams/matrix.js
And the data that gets fed to it can been seen in the source of this dynamic page: http://skyscraperpage.com/diagrams/?63000
So you can see that there is a large multi-dimension array that is created and filled with data, and then the JS file loops through that array and prints it as an HTML table.
I am now thinking of how I can get this Javascript to run as PHP code. Maybe create a conversion script which would translate the JS code into PHP code whenever I made changes to the JS code. Then this PHP file would be used for HTML-only users. Or is there somehow to specify language-construct changes to PHP so that it can actually interpret the JS file...? This is sounding really strange, but I like it!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.