Forum Moderators: open

Message Too Old, No Replies

clientside serverside

         

jackvull

11:52 am on Jan 5, 2006 (gmt 0)

10+ Year Member



Just a quick question:
If JavaScript is a clientside language then howcome if you type
<link rel="stylesheet" type="text/css" href="css/styles800.css">
it picks up the stylesheet correctly. Surely it would have to retrieve this from the server and just putting a relative link in will not work?

jackvull

11:57 am on Jan 5, 2006 (gmt 0)

10+ Year Member



<script language="javascript">
<!--
if (screen.width <= 800)
{
document.write('<link rel="stylesheet" type="text/css" href="css/styles800.css">');
}
else if (screen.width = 1024)
{
document.write('<link rel="stylesheet" type="text/css" href="css/styles1024.css">');
}
else if (screen.width > 1024)
{
document.write('<link rel="stylesheet" type="text/css" href="css/styles1024.css">');
}
else
{
document.write('<link rel="stylesheet" type="text/css" href="css/styles800.css">');
}
//-->
</script>

andye

12:10 pm on Jan 5, 2006 (gmt 0)

10+ Year Member



Surely it would have to retrieve this from the server

The 'client-side' versus 'server-side' distinction is about which computer executes the code, rather than where the original version of the file is saved.

Yes, all client-side code on the web must come from a file that the user's web browser retrieves from a web server. But the code is run in the user's web browser, on the user's PC.

Hope I've understood the question correctly, and that that's made it clearer.

a.

jackvull

12:46 pm on Jan 5, 2006 (gmt 0)

10+ Year Member



Yes, but the JavaScript code I have above determines the browser's screen width. It has to do this on the clientside machine.
It then determines which CSS file to use, but to correct the css file surely it has to get this from the server and with a relative link of css/styles800.css how will it know?

My confusion is coming from the fact that I thought the server decided to download the css file to the browser and as Javascript isn't running on the server, what does it do?

andye

4:13 pm on Jan 5, 2006 (gmt 0)

10+ Year Member



Hi jackvull,

I'm not certain I'm understanding your question right, but:

I thought the server decided to download the css file to the browser

No - the web browser requests a specific file from the server. Then the web server sends that file. So if the web browser requests styles800.css, the server will send styles800.css, and if the web browser requests styles1024.css, then the server sends styles1024.css.

The line:

<link rel="stylesheet" type="text/css" href="css/styles800.css">

is where the web browser requests that particular css file. The browser can ask for any filename it likes, and the server will try to send it (it might fail, e.g. if the file doesn't exist, but it'll try).

Does that answer your question? Sorry if I'm being obtuse...

best,
a.

Leosghost

4:20 pm on Jan 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Basically if the client machine is n't running "javascript allowed" no one is gonna see anything of your style sheets and thus not much of your site ..at least not how you planned it..

[edited by: Leosghost at 4:30 pm (utc) on Jan. 5, 2006]

jackvull

4:28 pm on Jan 5, 2006 (gmt 0)

10+ Year Member



I put a <noscript> tag in with a css link to cover this. Won't that work?

Thanks for the responses. My confusion was thinking from a server side scripting mechanism like PHP, which requests the file from the server while running on the server.