Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #3340 > unrolled thread

including CSS & JS on only pages that need that CSS & JS

Started byparis2venice <paris2venice@gmail.com>
First post2011-10-08 23:51 -0700
Last post2011-10-12 06:20 -0400
Articles 19 on this page of 39 — 11 participants

Back to article view | Back to comp.lang.php


Contents

  including CSS & JS on only pages that need that CSS & JS paris2venice <paris2venice@gmail.com> - 2011-10-08 23:51 -0700
    Re: including CSS & JS on only pages that need that CSS & JS Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-09 08:34 -0400
      Re: including CSS & JS on only pages that need that CSS & JS paris2venice <paris2venice@gmail.com> - 2011-10-10 02:22 -0700
        Re: including CSS & JS on only pages that need that CSS & JS Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-10 08:27 -0400
    Re: including CSS & JS on only pages that need that CSS & JS "Mr. B-o-B" <wtf.chuck@gmail.com> - 2011-10-09 08:46 -0500
      Re: including CSS & JS on only pages that need that CSS & JS Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-09 13:52 -0400
        Re: including CSS & JS on only pages that need that CSS & JS Luuk <Luuk@invalid.lan> - 2011-10-09 20:03 +0200
          Re: including CSS & JS on only pages that need that CSS & JS Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-09 15:08 -0400
    Re: including CSS & JS on only pages that need that CSS & JS Michael Joel <no@please.com> - 2011-10-09 16:31 -0400
      Re: including CSS & JS on only pages that need that CSS & JS Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-09 19:54 -0400
        Re: including CSS & JS on only pages that need that CSS & JS Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-09 20:03 -0400
        Re: including CSS & JS on only pages that need that CSS & JS "Mr. B-o-B" <wtf.chuck@gmail.com> - 2011-10-09 22:43 -0500
          Re: including CSS & JS on only pages that need that CSS & JS Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-10 08:30 -0400
            Re: including CSS & JS on only pages that need that CSS & JS Michael Joel <no@please.com> - 2011-10-10 13:04 -0400
              Re: including CSS & JS on only pages that need that CSS & JS Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-10 13:44 -0400
                Re: including CSS & JS on only pages that need that CSS & JS "Mr. B-o-B" <wtf.chuck@gmail.com> - 2011-10-10 21:35 -0500
                  Re: including CSS & JS on only pages that need that CSS & JS Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-10 23:04 -0400
                    Re: including CSS & JS on only pages that need that CSS & JS "Mr. B-o-B" <wtf.chuck@gmail.com> - 2011-10-10 22:14 -0500
                      Re: including CSS & JS on only pages that need that CSS & JS Michael Joel <no@please.com> - 2011-10-10 23:24 -0400
                      Re: including CSS & JS on only pages that need that CSS & JS Tim Streater <timstreater@greenbee.net> - 2011-10-11 10:33 +0100
                        Re: including CSS & JS on only pages that need that CSS & JS The Natural Philosopher <tnp@invalid.invalid> - 2011-10-11 11:29 +0100
                          Re: including CSS & JS on only pages that need that CSS & JS Tim Streater <timstreater@greenbee.net> - 2011-10-11 12:00 +0100
              Re: including CSS & JS on only pages that need that CSS & JS The Natural Philosopher <tnp@invalid.invalid> - 2011-10-10 19:34 +0100
                Re: including CSS & JS on only pages that need that CSS & JS Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-10 15:16 -0400
          Re: including CSS & JS on only pages that need that CSS & JS Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-10-10 23:17 +0200
            Re: including CSS & JS on only pages that need that CSS & JS Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-10 17:36 -0400
    Re: including CSS & JS on only pages that need that CSS & JS Denis McMahon <denismfmcmahon@gmail.com> - 2011-10-11 09:09 +0000
      Re: including CSS & JS on only pages that need that CSS & JS Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-10-11 14:11 +0200
      Re: including CSS & JS on only pages that need that CSS & JS Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-11 09:08 -0400
        Re: including CSS & JS on only pages that need that CSS & JS "Beauregard T. Shagnasty" <a.nony.mous@example.invalid> - 2011-10-11 13:29 +0000
          Re: including CSS & JS on only pages that need that CSS & JS Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-11 13:14 -0400
        Re: including CSS & JS on only pages that need that CSS & JS Denis McMahon <denismfmcmahon@gmail.com> - 2011-10-11 19:14 +0000
          Re: including CSS & JS on only pages that need that CSS & JS Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-10-11 22:38 +0200
        Re: including CSS & JS on only pages that need that CSS & JS paris2venice <paris2venice@gmail.com> - 2011-10-11 17:48 -0700
          Re: including CSS & JS on only pages that need that CSS & JS Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-11 21:51 -0400
            Re: including CSS & JS on only pages that need that CSS & JS paris2venice <paris2venice@gmail.com> - 2011-10-11 22:03 -0700
              Re: including CSS & JS on only pages that need that CSS & JS Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-12 06:19 -0400
          Re: including CSS & JS on only pages that need that CSS & JS Hans Olo <doctor@vaderlishious.com> - 2011-10-11 22:11 -0500
            Re: including CSS & JS on only pages that need that CSS & JS Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-12 06:20 -0400

Page 2 of 2 — ← Prev page 1 [2]


#3385

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2011-10-11 11:29 +0100
Message-ID<j715q6$2og$2@news.albasani.net>
In reply to#3383
Tim Streater wrote:
> In article <RyOkq.4249$%m.1042@newsfe05.iad>,
> "Mr. B-o-B" <wtf.chuck@gmail.com> wrote:
> 
>> On 10/10/2011 10:04 PM, Jerry Stuckle cried from the depths of the abyss:
>> > On 10/10/2011 10:35 PM, Mr. B-o-B wrote:
>> >> On 10/10/2011 12:44 PM, Jerry Stuckle cried from the depths of the 
>> abyss:
>> >>
>> >>>
>> >>> There are a lot of things that "work". That doesn't mean they are 
>> good
>> >>> things to do - as I pointed out in my first reply to you.
>> >>
>> >> You haven't actually pointed out anything. Forgot your med's again?
>> >>
>> >
>> > I pointed out several things wrong with your crappy code. But I know 
>> you
>> > can't read, much less write.
>> >
>>
>> Again, no you didn't.  Take your med's little Jerry, and go to bed.
> 
> Take his med's *what*? His med doesn't have a little Jerry - so what are 
> you *talking* about?
> 
bad grammar and punctuation.

How coders ever manage to write bug free code when they cant even write 
clear English can only be ascribed to the fact that they are happier 
talking to computers than human beings.

Try

"Take your meds, little Jerry, and go to bed."

[toc] | [prev] | [next] | [standalone]


#3386

FromTim Streater <timstreater@greenbee.net>
Date2011-10-11 12:00 +0100
Message-ID<timstreater-1724D7.12002411102011@news.individual.net>
In reply to#3385
In article <j715q6$2og$2@news.albasani.net>,
 The Natural Philosopher <tnp@invalid.invalid> wrote:

> Tim Streater wrote:
> > In article <RyOkq.4249$%m.1042@newsfe05.iad>,
> > "Mr. B-o-B" <wtf.chuck@gmail.com> wrote:
> > 
> >> On 10/10/2011 10:04 PM, Jerry Stuckle cried from the depths of the abyss:
> >> > On 10/10/2011 10:35 PM, Mr. B-o-B wrote:
> >> >> On 10/10/2011 12:44 PM, Jerry Stuckle cried from the depths of the 
> >> abyss:
> >> >>
> >> >>>
> >> >>> There are a lot of things that "work". That doesn't mean they are 
> >> good
> >> >>> things to do - as I pointed out in my first reply to you.
> >> >>
> >> >> You haven't actually pointed out anything. Forgot your med's again?
> >> >>
> >> >
> >> > I pointed out several things wrong with your crappy code. But I know 
> >> you
> >> > can't read, much less write.
> >> >
> >>
> >> Again, no you didn't.  Take your med's little Jerry, and go to bed.
> > 
> > Take his med's *what*? His med doesn't have a little Jerry - so what are 
> > you *talking* about?
> > 
> bad grammar and punctuation.
> 
> How coders ever manage to write bug free code when they cant even write 
> clear English can only be ascribed to the fact that they are happier 
> talking to computers than human beings.

Oh is *that* what it was. And there I was assuming the klod could write!

-- 
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted"  --  Bill of Rights 1689

[toc] | [prev] | [next] | [standalone]


#3370

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2011-10-10 19:34 +0100
Message-ID<j6vds7$822$3@news.albasani.net>
In reply to#3366
Michael Joel wrote:
> On Mon, 10 Oct 2011 08:30:15 -0400, Jerry Stuckle
> <jstucklex@attglobal.net> wrote:
> 
>>> ...............................
>>> On 10/9/2011 6:54 PM, Jerry Stuckle cried from the depths of the abyss:
> 
> I had a longer post but didn't want to say more than was needed...
> 
> You seem to have a problem with manners. Sorry - I don't want to fight
> but it is usually better not to call people and their advice names. If
> you have better give it, let the OP decide.
> 
> I use includes a lot.
> They work. They will work as long as your correct methods work. I use
> file names that make it clear what is in the files.
> 
> Mike

In thunderbird:

tools->filters->add filter->jstucklex@att.net


My life has improved immensely after these simple steps.

[toc] | [prev] | [next] | [standalone]


#3371

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-10-10 15:16 -0400
Message-ID<j6vg9u$vn1$1@dont-email.me>
In reply to#3370
On 10/10/2011 2:34 PM, The Natural Philosopher wrote:
> Michael Joel wrote:
>> On Mon, 10 Oct 2011 08:30:15 -0400, Jerry Stuckle
>> <jstucklex@attglobal.net> wrote:
>>
>>>> ...............................
>>>> On 10/9/2011 6:54 PM, Jerry Stuckle cried from the depths of the abyss:
>>
>> I had a longer post but didn't want to say more than was needed...
>>
>> You seem to have a problem with manners. Sorry - I don't want to fight
>> but it is usually better not to call people and their advice names. If
>> you have better give it, let the OP decide.
>>
>> I use includes a lot.
>> They work. They will work as long as your correct methods work. I use
>> file names that make it clear what is in the files.
>>
>> Mike
>
> In thunderbird:
>
> tools->filters->add filter->jstucklex@att.net
>
>
> My life has improved immensely after these simple steps.

Yes, ignorance is bliss.  And you're about as blissful as they come.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#3372

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2011-10-10 23:17 +0200
Message-ID<9489429.VONEhFrKcU@PointedEars.de>
In reply to#3354
Mr. B-o-B wrote:

> On 10/9/2011 6:54 PM, Jerry Stuckle cried from the depths of the abyss:
>> And files should be included using link tags, not directly included in
>> the source file directly (unless they are specific to this page - in
>> which case there is no need for conditional includes). That way file can
>> be cached by the browser and/or routers between the web server and the
>> client, decreasing both network traffic and server load.
> 
> Again, my original post fits these specs:
> 
> if (@isset $jerrys_css) {
> echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"jerry_css.css\"
> />";
> }
> 
> Then just set $jerry_css = 1 when needed.  Imagine that.  You are not
> decreasing network traffic, not increasing server load, cache is
> irrelevant as it's only cached in the pages that need it, you are using
> .js/.css via link tags.

This looks increasingly like blind teaching the blind.  As the subject is in 
fact partially on-topic here, since PHP can be used server-side:

0. Routers do not cache HTTP requests.  They usually work on lower levels
   of the TCP/IP stack, the Transport (TCP) and Internet Layer (IP), and
   usually see only TCP and IP packets.  Not only is a HTTP message usually
   split into several IP packets, but also is the payload transported by
   such a packet reduced so that the packet size does not exceed the MTU of
   the link, considering the header information of the packet as well.

   So we can safely dismiss the suggestion that the composition of Web
   resources could affect packet caching, if that even happens (routers
   usually cache *routing information*), as completely b…ogus.

1. You cannot "use .js via link tags".  Client-side scripts have to be
   included using `script' elements.

   It is the best current practice that all client-side scripts required
   for a document be included with one request, unless it is feasible and
   more efficient to load some of them dynamically when needed.  Which
   usually means that the request triggers a server-side script that
   composes the response for that one script.

2. It makes no difference to the number of requests whether you include
   other stylesheets with the CSS @import rule or the (X)HTML `link'
   element.  Cacheability is equal, too, as with the CSS directive the
   source code does not change as well.  [The same applies for scripts
   being loaded dynamically.]

   The main difference is in compatibility.  Rather ancient user agents
   would not support the `@import' rule but would support the `link'
   element:

   <http://w3development.de/css/hide_css_from_browsers/import/>

   [Much the same applies for dynamic script loading.  It usually requires
    XHR support or sufficient DOM support, while the plain `script' element
    is more compatible and reliable.]

3. It does make a difference to the loading speed of a Web site and the
   network traffic caused by it if you create one response from content of
   several CSS resources, as that is only one request.  Doing so is the best
   current practice.  As for caching, it rarely makes sense to exclude CSS
   rules from the generated response even if they are not used. 
   It really is a matter of loading speed/traffic vs. cacheability; usually,
   loading speed is considered to be more important, as local caches are
   usually large enough to handle the differences and visitors do not like
   to wait.

4. Requests for client-side scripts should be caused last, at least after
   the requests for stylesheets:

   <http://code.google.com/speed/page-
speed/docs/rtt.html#PutStylesBeforeScripts>


Bottom line: Fewer requests and smaller responses are better.

I have started writing a general resource builder in PHP to do that.  So far 
it works without problems for client-side scripts even in a production 
environment:

<http://PointedEars.de/websvn/filedetails.php?repname=JSX&path=%2Ftrunk%2Fbuilder.php>

(The ultimate goal is that it resolves dependencies of resources 
automatically.)

Constructive comments are welcome.


PointedEars
-- 
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
  -- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)

[toc] | [prev] | [next] | [standalone]


#3373

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-10-10 17:36 -0400
Message-ID<j6voh6$tgf$1@dont-email.me>
In reply to#3372
On 10/10/2011 5:17 PM, Thomas 'PointedEars' Lahn wrote:
> Mr. B-o-B wrote:
>
>> On 10/9/2011 6:54 PM, Jerry Stuckle cried from the depths of the abyss:
>>> And files should be included using link tags, not directly included in
>>> the source file directly (unless they are specific to this page - in
>>> which case there is no need for conditional includes). That way file can
>>> be cached by the browser and/or routers between the web server and the
>>> client, decreasing both network traffic and server load.
>>
>> Again, my original post fits these specs:
>>
>> if (@isset $jerrys_css) {
>> echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"jerry_css.css\"
>> />";
>> }
>>
>> Then just set $jerry_css = 1 when needed.  Imagine that.  You are not
>> decreasing network traffic, not increasing server load, cache is
>> irrelevant as it's only cached in the pages that need it, you are using
>> .js/.css via link tags.
>
> This looks increasingly like blind teaching the blind.  As the subject is in
> fact partially on-topic here, since PHP can be used server-side:
>

Of course PHP can be used server side. But that's not the point. 
Unfortunately, you are unable to understand some very simple concepts. 
Let me try to educate you (although I already know that's about as 
possible as teaching a pig to sing):


> 0. Routers do not cache HTTP requests.  They usually work on lower levels
>     of the TCP/IP stack, the Transport (TCP) and Internet Layer (IP), and
>     usually see only TCP and IP packets.  Not only is a HTTP message usually
>     split into several IP packets, but also is the payload transported by
>     such a packet reduced so that the packet size does not exceed the MTU of
>     the link, considering the header information of the packet as well.
>
>     So we can safely dismiss the suggestion that the composition of Web
>     resources could affect packet caching, if that even happens (routers
>     usually cache *routing information*), as completely b…ogus.
>

Intelligent routers/proxies can.

> 1. You cannot "use .js via link tags".  Client-side scripts have to be
>     included using `script' elements.
>
>     It is the best current practice that all client-side scripts required
>     for a document be included with one request, unless it is feasible and
>     more efficient to load some of them dynamically when needed.  Which
>     usually means that the request triggers a server-side script that
>     composes the response for that one script.
>

Not via a link tag.  But it can be loaded externally, i.e.

<script src="myjs.js">

> 2. It makes no difference to the number of requests whether you include
>     other stylesheets with the CSS @import rule or the (X)HTML `link'
>     element.  Cacheability is equal, too, as with the CSS directive the
>     source code does not change as well.  [The same applies for scripts
>     being loaded dynamically.]
>

Incorrect.  A CSS file that is linked from several different pages can 
be cached by the client.  Including the css in every page means it will 
NOT be cached (unless that page is cached).

>     The main difference is in compatibility.  Rather ancient user agents
>     would not support the `@import' rule but would support the `link'
>     element:
>
>     <http://w3development.de/css/hide_css_from_browsers/import/>
>
>     [Much the same applies for dynamic script loading.  It usually requires
>      XHR support or sufficient DOM support, while the plain `script' element
>      is more compatible and reliable.]
>

Again, incorrect.  XHR and DOM support are not required; they have been 
part of the HTML spec for years.

> 3. It does make a difference to the loading speed of a Web site and the
>     network traffic caused by it if you create one response from content of
>     several CSS resources, as that is only one request.  Doing so is the best
>     current practice.  As for caching, it rarely makes sense to exclude CSS
>     rules from the generated response even if they are not used.
>     It really is a matter of loading speed/traffic vs. cacheability; usually,
>     loading speed is considered to be more important, as local caches are
>     usually large enough to handle the differences and visitors do not like
>     to wait.
>

Yes and no.  A blanket statement like this is dangerous.  The first time 
a large CSS file is requested it can be cached.  But if it is a large 
file, it may take a lot of time to load that first time - and normally 
the first page is the most critical (people won't wait long for a site 
if it starts out slow).

However, most CSS files are not that big to cause a problem, so in 
general it can be a good idea.

> 4. Requests for client-side scripts should be caused last, at least after
>     the requests for stylesheets:
>
>     <http://code.google.com/speed/page-
> speed/docs/rtt.html#PutStylesBeforeScripts>
>
>

That's one opinion - but it is not necessarily true for all browsers. 
Some will not display anything until the entire page is loaded; others 
will display during the load phase.

It also depends on whether you have any client side scripting code which 
runs on page load; if so, then those scripts should be loaded first.

> Bottom line: Fewer requests and smaller responses are better.
>

In general, yes, but again, not always.

> I have started writing a general resource builder in PHP to do that.  So far
> it works without problems for client-side scripts even in a production
> environment:
>
> <http://PointedEars.de/websvn/filedetails.php?repname=JSX&path=%2Ftrunk%2Fbuilder.php>
>
> (The ultimate goal is that it resolves dependencies of resources
> automatically.)
>
> Constructive comments are welcome.
>
>
> PointedEars


But none of any of this has anything to do with PHP.  If you claim that 
is so, please show me where any of this can be found in the PHP manual.


-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#3382

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2011-10-11 09:09 +0000
Message-ID<4e9407bd$0$28439$a8266bb1@newsreader.readnews.com>
In reply to#3340
On Sat, 08 Oct 2011 23:51:10 -0700, paris2venice wrote:

> I'm still a newbie at PHP.  What would be the right way to include CSS
> and Javascript such that I could add CSS and JS just for those pages
> that need it?

The way I would do it, which doubtless various other people will say is 
incorrect for various reasons, is as follows:

Firstly, separate out the css and js into individual files. It's much 
easier to maintain the js and css in separate files than it is  
encapsulated inside php.

Name each such file according to the styles or functions it contains, 
then use code something like this:

<?php

// echo the doctype and opening html tag here

echo "<head>\n";

// echo any meta headers eg content-type here

echo "<title>{$pagetitle}</title>\n";

// then for each javascript file, either:

if (some_condition) echo "<script type='text/javascript' 
src='{$jsfilenamex}'></script>\n";

// or:

if (some_condition) echo "<script type='text/javascript' 
src='{$jsfilenamex}' />\n";

// and for each css file, either:

if (some_condition) echo "<link href='{$cssfileurlx}' rel='stylesheet' 
type='text/css'>\n";

// or:

if (some_condition) echo "<link href='{$cssfileurlx}' rel='stylesheet' 
type='text/css' />\n";

// echo any other html "head" contents here

echo "</head>\n";

?>

Rgds

Denis McMahon

[toc] | [prev] | [next] | [standalone]


#3388

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2011-10-11 14:11 +0200
Message-ID<1712757.iOTu7YrNUb@PointedEars.de>
In reply to#3382
Denis McMahon wrote:

> On Sat, 08 Oct 2011 23:51:10 -0700, paris2venice wrote:
>> I'm still a newbie at PHP.  What would be the right way to include CSS
>> and Javascript such that I could add CSS and JS just for those pages
>> that need it?
> 
> The way I would do it, which doubtless various other people will say is
> incorrect for various reasons,

That is the way of an ignorant.  Instead of trying to understand the 
reasoning in the arguments, and either challenge it, or act and recommend 
accordingly, you are simply ignoring it as if that would change anything.

> is as follows:

It is incorrect in that it is hard to maintain and comparably inefficient.  
First of all, you should not use consecutive `echo' statements where simply 
leaving (or not entering) PHP mode suffices.  In essence, not

  <?php
    echo "foo";
  ?>

but

  foo

or

<?php
  …
?>
  foo
<?php
  …
?>
 
> Firstly, separate out the css and js into individual files. It's much
> easier to maintain the js and css in separate files than it is
> encapsulated inside php.

I accept your premise, I reject your conclusion.
 
> Name each such file according to the styles or functions it contains,
> then use code something like this:
> 
> <?php
> 
> // echo the doctype and opening html tag here
> 
> echo "<head>\n";
> 
> // echo any meta headers eg content-type here
> 
> echo "<title>{$pagetitle}</title>\n";
> 
> // then for each javascript file, either:
> 
> if (some_condition) echo "<script type='text/javascript'
> src='{$jsfilenamex}'></script>\n";
> 
> // or:
> 
> if (some_condition) echo "<script type='text/javascript'
> src='{$jsfilenamex}' />\n";

That makes one request for each file.  I have already explained why that 
approach is unwise at best, what a better approach is and why.
 
> // and for each css file, either:
> 
> if (some_condition) echo "<link href='{$cssfileurlx}' rel='stylesheet'
> type='text/css'>\n";
> 
> // or:
> 
> if (some_condition) echo "<link href='{$cssfileurlx}' rel='stylesheet'
> type='text/css' />\n";

One request for each file, the content included verbatim, and XHTML syntax 
with no evidence that XHTML is required.  One can hardly do worse.
 

PointedEars
-- 
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
  -- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)

[toc] | [prev] | [next] | [standalone]


#3389

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-10-11 09:08 -0400
Message-ID<j71f50$b2q$1@dont-email.me>
In reply to#3382
On 10/11/2011 5:09 AM, Denis McMahon wrote:
> On Sat, 08 Oct 2011 23:51:10 -0700, paris2venice wrote:
>
>> I'm still a newbie at PHP.  What would be the right way to include CSS
>> and Javascript such that I could add CSS and JS just for those pages
>> that need it?
>
> The way I would do it, which doubtless various other people will say is
> incorrect for various reasons, is as follows:
>
> Firstly, separate out the css and js into individual files. It's much
> easier to maintain the js and css in separate files than it is
> encapsulated inside php.
>

Very definitely.  It also increases reusability.

> Name each such file according to the styles or functions it contains,
> then use code something like this:
>
> <?php
>
> // echo the doctype and opening html tag here
>
> echo "<head>\n";
>
> // echo any meta headers eg content-type here
>

There is no need to echo these.  You can just code them as plain html. 
Easier to read and maintain.

> echo "<title>{$pagetitle}</title>\n";
>

OK, this may be something good to echo.  The real question is - where 
does $pagetitle come from?  If it's from a database, then this is good. 
  But if you just set it at the top of the script, again, why complicate 
things?


> // then for each javascript file, either:
>
> if (some_condition) echo "<script type='text/javascript'
> src='{$jsfilenamex}'></script>\n";
>
> // or:
>
> if (some_condition) echo "<script type='text/javascript'
> src='{$jsfilenamex}' />\n";
>

Here you do need PHP for the conditional.

> // and for each css file, either:
>
> if (some_condition) echo "<link href='{$cssfileurlx}' rel='stylesheet'
> type='text/css'>\n";
>
> // or:
>
> if (some_condition) echo "<link href='{$cssfileurlx}' rel='stylesheet'
> type='text/css' />\n";
>

I fail to see the difference between the two.

> // echo any other html "head" contents here
>
> echo "</head>\n";
>
> ?>
>

Again, no need to echo what can be done more simply in plain html.

> Rgds
>
> Denis McMahon

The only other comment I have is - if you're using the majority of the 
javascript and css code in your pages, why even split them up?  Placing 
all you css of javascript in one file can actually cut traffic and 
overhead because the browser will cache the file once and reuse it.


-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#3390

From"Beauregard T. Shagnasty" <a.nony.mous@example.invalid>
Date2011-10-11 13:29 +0000
Message-ID<j71gcn$a0g$1@dont-email.me>
In reply to#3389
Jerry Stuckle wrote:

>> if (some_condition) echo "<link href='{$cssfileurlx}' rel='stylesheet'
>> type='text/css'>\n";
>>
>> // or:
>>
>> if (some_condition) echo "<link href='{$cssfileurlx}' rel='stylesheet'
>> type='text/css' />\n";
>>
>>
> I fail to see the difference between the two.

The second one has a trailing "/" for XHTML ...

-- 
   -bts
   -This space for rent, but the price is high

[toc] | [prev] | [next] | [standalone]


#3392

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-10-11 13:14 -0400
Message-ID<j71tha$i42$1@dont-email.me>
In reply to#3390
On 10/11/2011 9:29 AM, Beauregard T. Shagnasty wrote:
> Jerry Stuckle wrote:
>
>>> if (some_condition) echo "<link href='{$cssfileurlx}' rel='stylesheet'
>>> type='text/css'>\n";
>>>
>>> // or:
>>>
>>> if (some_condition) echo "<link href='{$cssfileurlx}' rel='stylesheet'
>>> type='text/css' />\n";
>>>
>>>
>> I fail to see the difference between the two.
>
> The second one has a trailing "/" for XHTML ...
>

Ah, missed that, Beauregard.  Thanks.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#3393

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2011-10-11 19:14 +0000
Message-ID<4e94957d$0$28592$a8266bb1@newsreader.readnews.com>
In reply to#3389
On Tue, 11 Oct 2011 09:08:46 -0400, Jerry Stuckle wrote:

> > either "<link .....> or <link .... />"

> I fail to see the difference between the two.

the tag closures, I don't know if OP is using html 4, xhtml 1.1 or 
something else.

> The only other comment I have is - if you're using the majority of the
> javascript and css code in your pages, why even split them up?

I'm allowing for the OP's "such that I could add CSS and JS just for 
those pages that need it?" and the fact he might have different css / js 
files used on different web pages.

Rgds

Denis McMahon

[toc] | [prev] | [next] | [standalone]


#3394

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2011-10-11 22:38 +0200
Message-ID<3268351.2Fxpk1BWYv@PointedEars.de>
In reply to#3393
Denis McMahon wrote:

> On Tue, 11 Oct 2011 09:08:46 -0400, Jerry Stuckle wrote:
>> > either "<link .....> or <link .... />"
> 
>> I fail to see the difference between the two.
> 
> the tag closures, I don't know if OP is using html 4, xhtml 1.1 or
> something else.

Ahh yes, my mistake there.


PointedEars 
-- 
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
  -- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)

[toc] | [prev] | [next] | [standalone]


#3395

Fromparis2venice <paris2venice@gmail.com>
Date2011-10-11 17:48 -0700
Message-ID<c991da2b-1181-4102-a26a-1533948e0e5f@v38g2000prm.googlegroups.com>
In reply to#3389
On Oct 11, 6:08 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 10/11/2011 5:09 AM, Denis McMahon wrote:
>
> > On Sat, 08 Oct 2011 23:51:10 -0700, paris2venice wrote:
>
> >> I'm still a newbie at PHP.  What would be the right way to include CSS
> >> and Javascript such that I could add CSS and JS just for those pages
> >> that need it?
>
> > The way I would do it, which doubtless various other people will say is
> > incorrect for various reasons, is as follows:
>
> > Firstly, separate out the css and js into individual files. It's much
> > easier to maintain the js and css in separate files than it is
> > encapsulated inside php.
>
> Very definitely.  It also increases reusability.
>
> > Name each such file according to the styles or functions it contains,
> > then use code something like this:
>
> > <?php
>
> > // echo the doctype and opening html tag here
>
> > echo "<head>\n";
>
> > // echo any meta headers eg content-type here
>
> There is no need to echo these.  You can just code them as plain html.
> Easier to read and maintain.
>
> > echo "<title>{$pagetitle}</title>\n";
>
> OK, this may be something good to echo.  The real question is - where
> does $pagetitle come from?  If it's from a database, then this is good.
>   But if you just set it at the top of the script, again, why complicate
> things?
>
> > // then for each javascript file, either:
>
> > if (some_condition) echo "<script type='text/javascript'
> > src='{$jsfilenamex}'></script>\n";
>
> > // or:
>
> > if (some_condition) echo "<script type='text/javascript'
> > src='{$jsfilenamex}' />\n";
>
> Here you do need PHP for the conditional.
>
> > // and for each css file, either:
>
> > if (some_condition) echo "<link href='{$cssfileurlx}' rel='stylesheet'
> > type='text/css'>\n";
>
> > // or:
>
> > if (some_condition) echo "<link href='{$cssfileurlx}' rel='stylesheet'
> > type='text/css' />\n";
>
> I fail to see the difference between the two.
>
> > // echo any other html "head" contents here
>
> > echo "</head>\n";
>
> > ?>
>
> Again, no need to echo what can be done more simply in plain html.
>
> > Rgds
>
> > Denis McMahon
>
> The only other comment I have is - if you're using the majority of the
> javascript and css code in your pages, why even split them up?  Placing
> all you css of javascript in one file can actually cut traffic and
> overhead because the browser will cache the file once and reuse it.


Jerry, I don't get it.  What did I say that led you to believe I was
doing anything else except what both you and PointedEars describe
above?   I'm not faulting you -- I obviously did not communicate
effectively with the HTML comments I used.

My include files are nothing but pure HTML.  Thus, I'm not mixing the
DOCTYPE with CSS and never have.  I've been creating websites almost
since the inception of the web (1995) so I do know what I'm doing and
I certainly don't need to read a book on HTML or CSS.  PHP?  Yes.  But
if what I asked was so simple, there wouldn't be 33 posts already.

Thanks very much to everyone who contributed.  I sincerely appreciate
your efforts to help.

[toc] | [prev] | [next] | [standalone]


#3396

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-10-11 21:51 -0400
Message-ID<j72rrb$s0j$1@dont-email.me>
In reply to#3395
On 10/11/2011 8:48 PM, paris2venice wrote:
>
>
> Jerry, I don't get it.  What did I say that led you to believe I was
> doing anything else except what both you and PointedEars describe
> above?   I'm not faulting you -- I obviously did not communicate
> effectively with the HTML comments I used.
>
> My include files are nothing but pure HTML.  Thus, I'm not mixing the
> DOCTYPE with CSS and never have.  I've been creating websites almost
> since the inception of the web (1995) so I do know what I'm doing and
> I certainly don't need to read a book on HTML or CSS.  PHP?  Yes.  But
> if what I asked was so simple, there wouldn't be 33 posts already.
>
> Thanks very much to everyone who contributed.  I sincerely appreciate
> your efforts to help.

As you said in your very first post in this thread:

<?
    php require_once './css.php';             /* css.php contains
doctype, meta & css needed universally */
?>

Look at your own comment.

Additionally, .css files should not be named .php (they don't contain 
any PHP code).  Neither should they have DOCTYPE, META or anything else 
not CSS.  And you shouldn't include() them - you should LINK to them.

And it is simple.  But unfortunately there are a few trolls who frequent 
this group all too regularly.  Many of the posts are from them.

Also, it really doesn't matter how long you've been doing it.  You could 
have been doing it wrong for the last 15 years just as easily as you 
could have been doing it right.

And your comments at least indicate you've been doing it wrong.

And BTW - if you have been doing it for that many years, then you should 
understand why having dozens of css files is not necessarily good. 
Often times one css file performs better.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#3398

Fromparis2venice <paris2venice@gmail.com>
Date2011-10-11 22:03 -0700
Message-ID<d142ff83-d8db-42e3-a47f-f45518624b52@u12g2000prm.googlegroups.com>
In reply to#3396
On Oct 11, 6:51 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 10/11/2011 8:48 PM, paris2venice wrote:
>
>
>
> > Jerry, I don't get it.  What did I say that led you to believe I was
> > doing anything else except what both you and PointedEars describe
> > above?   I'm not faulting you -- I obviously did not communicate
> > effectively with the HTML comments I used.
>
> > My include files are nothing but pure HTML.  Thus, I'm not mixing the
> > DOCTYPE with CSS and never have.  I've been creating websites almost
> > since the inception of the web (1995) so I do know what I'm doing and
> > I certainly don't need to read a book on HTML or CSS.  PHP?  Yes.  But
> > if what I asked was so simple, there wouldn't be 33 posts already.
>
> > Thanks very much to everyone who contributed.  I sincerely appreciate
> > your efforts to help.
>
> As you said in your very first post in this thread:
>
> <?
>     php require_once './css.php';             /* css.php contains
> doctype, meta & css needed universally */
> ?>
>
> Look at your own comment.

I did acknowledge my miscommunication.  I should have written 'css
links'.  However, it *was* just a comment and I didn't think anyone
would misunderstand my meaning and I certainly didn't think anyone
would think I mixed my DOCTYPE and CSS.


> Additionally, .css files should not be named .php (they don't contain
> any PHP code).  Neither should they have DOCTYPE, META or anything else
> not CSS.  And you shouldn't include() them - you should LINK to them.

What's on the left side of an extension is kind of a personal choice,
isn't it?  It can be whatever I want it to be.  To be honest, I don't
think I'll ever give credit to anyone anywhere for exceeding my own
filename conventions.  Remember, it was just a comment.  I don't even
have a file named css.php and, if I did, that would be my personal
preference.


> And it is simple.  But unfortunately there are a few trolls who frequent
> this group all too regularly.  Many of the posts are from them.
>
> Also, it really doesn't matter how long you've been doing it.  You could
> have been doing it wrong for the last 15 years just as easily as you
> could have been doing it right.
>
> And your comments at least indicate you've been doing it wrong.

It indicates nothing.  They're comments.


> And BTW - if you have been doing it for that many years, then you should
> understand why having dozens of css files is not necessarily good.
> Often times one css file performs better.

Go to the top 100 major sites on the Internet and tell me if you find
one that has only one CSS file.  If you find just one, I'll go along
with your idea.

[toc] | [prev] | [next] | [standalone]


#3400

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-10-12 06:19 -0400
Message-ID<j73pj1$idp$1@dont-email.me>
In reply to#3398
On 10/12/2011 1:03 AM, paris2venice wrote:
> On Oct 11, 6:51 pm, Jerry Stuckle<jstuck...@attglobal.net>  wrote:
>> On 10/11/2011 8:48 PM, paris2venice wrote:
>>
>>
>>
>>> Jerry, I don't get it.  What did I say that led you to believe I was
>>> doing anything else except what both you and PointedEars describe
>>> above?   I'm not faulting you -- I obviously did not communicate
>>> effectively with the HTML comments I used.
>>
>>> My include files are nothing but pure HTML.  Thus, I'm not mixing the
>>> DOCTYPE with CSS and never have.  I've been creating websites almost
>>> since the inception of the web (1995) so I do know what I'm doing and
>>> I certainly don't need to read a book on HTML or CSS.  PHP?  Yes.  But
>>> if what I asked was so simple, there wouldn't be 33 posts already.
>>
>>> Thanks very much to everyone who contributed.  I sincerely appreciate
>>> your efforts to help.
>>
>> As you said in your very first post in this thread:
>>
>> <?
>>      php require_once './css.php';             /* css.php contains
>> doctype, meta&  css needed universally */
>> ?>
>>
>> Look at your own comment.
>
> I did acknowledge my miscommunication.  I should have written 'css
> links'.  However, it *was* just a comment and I didn't think anyone
> would misunderstand my meaning and I certainly didn't think anyone
> would think I mixed my DOCTYPE and CSS.
>

"Just a comment"?  Comments are important in code - but incorrect 
comments are worse than no comment at all.

And you'd be surprised what some people do.

>
>> Additionally, .css files should not be named .php (they don't contain
>> any PHP code).  Neither should they have DOCTYPE, META or anything else
>> not CSS.  And you shouldn't include() them - you should LINK to them.
>
> What's on the left side of an extension is kind of a personal choice,
> isn't it?  It can be whatever I want it to be.  To be honest, I don't
> think I'll ever give credit to anyone anywhere for exceeding my own
> filename conventions.  Remember, it was just a comment.  I don't even
> have a file named css.php and, if I did, that would be my personal
> preference.
>

Yes and no.  For the left of the '.' you should have some conventions to 
help keep things straight.  And in larger multi-programmer projects you 
will generally be told what the file names will be.

But I wasn't referring to what's on the left - I was referring to the 
extension, which does mean something.  And incorrect comments are worse 
than no comments at all.


>
>> And it is simple.  But unfortunately there are a few trolls who frequent
>> this group all too regularly.  Many of the posts are from them.
>>
>> Also, it really doesn't matter how long you've been doing it.  You could
>> have been doing it wrong for the last 15 years just as easily as you
>> could have been doing it right.
>>
>> And your comments at least indicate you've been doing it wrong.
>
> It indicates nothing.  They're comments.
>

If that's your attitude about comments, I wouldn't want to be anywhere 
around anything you code.

>
>> And BTW - if you have been doing it for that many years, then you should
>> understand why having dozens of css files is not necessarily good.
>> Often times one css file performs better.
>
> Go to the top 100 major sites on the Internet and tell me if you find
> one that has only one CSS file.  If you find just one, I'll go along
> with your idea.
>
>

You've got one of the top 100 major sites?  If so, great.  Otherwise, 
you're comparing apples and oranges.

But you've already shown you don't want to learn.  You just want to be 
validated and will argue with anyone who disagrees with you.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#3397

FromHans Olo <doctor@vaderlishious.com>
Date2011-10-11 22:11 -0500
Message-ID<5C7lq.7274$Gy7.3031@newsfe16.iad>
In reply to#3395
On 10/11/2011 7:48 PM, paris2venice cried from the depths of the abyss:
>
> Jerry, I don't get it.  What did I say that led you to believe I was
> doing anything else except what both you and PointedEars describe
> above?   I'm not faulting you -- I obviously did not communicate
> effectively with the HTML comments I used.

Don't bother trying to figure this one out.  He likes to inject crap 
into the equation then froth at the mouth endlessly about it.  Things 
are usually so off topic by the end of the thread it's comical.  Like 
dog crap on a tire, it just goes round and round.

>
> My include files are nothing but pure HTML.  Thus, I'm not mixing the
> DOCTYPE with CSS and never have.  I've been creating websites almost
> since the inception of the web (1995) so I do know what I'm doing and
> I certainly don't need to read a book on HTML or CSS.  PHP?  Yes.  But
> if what I asked was so simple, there wouldn't be 33 posts already.
>

There probably would have only been 2 or 3 until you know who started 
injecting....

> Thanks very much to everyone who contributed.  I sincerely appreciate
> your efforts to help.

[toc] | [prev] | [next] | [standalone]


#3401

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-10-12 06:20 -0400
Message-ID<j73pl8$idp$2@dont-email.me>
In reply to#3397
On 10/11/2011 11:11 PM, Hans Olo wrote:
> On 10/11/2011 7:48 PM, paris2venice cried from the depths of the abyss:
>>
>> Jerry, I don't get it. What did I say that led you to believe I was
>> doing anything else except what both you and PointedEars describe
>> above? I'm not faulting you -- I obviously did not communicate
>> effectively with the HTML comments I used.
>
> Don't bother trying to figure this one out. He likes to inject crap into
> the equation then froth at the mouth endlessly about it. Things are
> usually so off topic by the end of the thread it's comical. Like dog
> crap on a tire, it just goes round and round.
>

Ah, another troll being heard from. I tried to steer this to a more 
appropriate newsgroup right at the start.

>>
>> My include files are nothing but pure HTML. Thus, I'm not mixing the
>> DOCTYPE with CSS and never have. I've been creating websites almost
>> since the inception of the web (1995) so I do know what I'm doing and
>> I certainly don't need to read a book on HTML or CSS. PHP? Yes. But
>> if what I asked was so simple, there wouldn't be 33 posts already.
>>
>
> There probably would have only been 2 or 3 until you know who started
> injecting....
>
>> Thanks very much to everyone who contributed. I sincerely appreciate
>> your efforts to help.
>


-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.php


csiph-web