FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » including CSS & JS on only pages that need that CSS & JS
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
including CSS & JS on only pages that need that CSS & JS [message #175565] Sun, 09 October 2011 06:51 Go to next message
paris2venice is currently offline  paris2venice
Messages: 9
Registered: October 2011
Karma: 0
Junior Member
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?

Would it be something like this? Is this how you do it?

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

<!-- link href= calls to CSS needed on local page only -->

<?
php require_once './js.php'; /* js.php contains
javascript calls needed universally */
?>

<!-- script type="text/javascript" calls to Javascript needed on
local page only -->
</head>


Thanks a bunch for your help.
Re: including CSS & JS on only pages that need that CSS & JS [message #175569 is a reply to message #175565] Sun, 09 October 2011 12:34 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 10/9/2011 2:51 AM, 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?
>
> Would it be something like this? Is this how you do it?
>
> <?
> php require_once './css.php'; /* css.php contains
> doctype, meta& css needed universally */
> ?>
>
> <!-- link href= calls to CSS needed on local page only -->
>
> <?
> php require_once './js.php'; /* js.php contains
> javascript calls needed universally */
> ?>
>
> <!-- script type="text/javascript" calls to Javascript needed on
> local page only -->
> </head>
>
>
> Thanks a bunch for your help.

I'm not sure what you're trying to do here, but these aren't PHP
questions. You're only using PHP to include the files.

You're asking basic layout file layout questions, which vary widely.
The includes can be done in many ways.

The first thing you need to do is learn about various ways to structure
your files. For instance, don't mix your DOCTYPE and other header
information with CSS.

I would suggest you start with a book on basic programming for the web,
including html, css, etc.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: including CSS & JS on only pages that need that CSS & JS [message #175570 is a reply to message #175565] Sun, 09 October 2011 13:46 Go to previous messageGo to next message
Mr. B-o-B is currently offline  Mr. B-o-B
Messages: 42
Registered: April 2011
Karma: 0
Member
On 10/9/2011 1:51 AM, paris2venice cried from the depths of the abyss:
> 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?
>
> Would it be something like this? Is this how you do it?
>
> <?
> php require_once './css.php'; /* css.php contains
> doctype, meta& css needed universally */
> ?>
>
> <!-- link href= calls to CSS needed on local page only -->
>
> <?
> php require_once './js.php'; /* js.php contains
> javascript calls needed universally */
> ?>
>
> <!-- script type="text/javascript" calls to Javascript needed on
> local page only -->
> </head>

As Jerry mentioned separate DOCTYPE from your CSS for starter. Mixing
nonrelated things just leads to a clusterf*ck down the road. Keep it
seperate/keep it clean. It's worth it in the long run.

An easy way to pull this off is to put all your javascripts and css into
a header type file like so (each CSS & JS seperately):

if (@isset $javascript01){
put code here
}

if (@isset $javascript02){
put code here
}

if (@isset $css01){
put code here
}
etc....

On your pages include the header file. Then on the pages/files you need
to use the $javascript01 & or $css01, just set the variable name you
created in the header file:

$javascript01 = 1

Just that easy.
Re: including CSS & JS on only pages that need that CSS & JS [message #175571 is a reply to message #175570] Sun, 09 October 2011 17:52 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 10/9/2011 9:46 AM, Mr. B-o-B wrote:
> On 10/9/2011 1:51 AM, paris2venice cried from the depths of the abyss:
>> 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?
>>
>> Would it be something like this? Is this how you do it?
>>
>> <?
>> php require_once './css.php'; /* css.php contains
>> doctype, meta& css needed universally */
>> ?>
>>
>> <!-- link href= calls to CSS needed on local page only -->
>>
>> <?
>> php require_once './js.php'; /* js.php contains
>> javascript calls needed universally */
>> ?>
>>
>> <!-- script type="text/javascript" calls to Javascript needed on
>> local page only -->
>> </head>
>
> As Jerry mentioned separate DOCTYPE from your CSS for starter. Mixing
> nonrelated things just leads to a clusterf*ck down the road. Keep it
> seperate/keep it clean. It's worth it in the long run.
>
> An easy way to pull this off is to put all your javascripts and css into
> a header type file like so (each CSS & JS seperately):
>
> if (@isset $javascript01){
> put code here
> }
>
> if (@isset $javascript02){
> put code here
> }
>
> if (@isset $css01){
> put code here
> }
> etc....
>
> On your pages include the header file. Then on the pages/files you need
> to use the $javascript01 & or $css01, just set the variable name you
> created in the header file:
>
> $javascript01 = 1
>
> Just that easy.
>

There are a number of reasons you wouldn't want to do it this way - but
all are off topic in a PHP newsgroups.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: including CSS & JS on only pages that need that CSS & JS [message #175572 is a reply to message #175571] Sun, 09 October 2011 18:03 Go to previous messageGo to next message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma: 0
Senior Member
On 09-10-2011 19:52, Jerry Stuckle wrote:
> On 10/9/2011 9:46 AM, Mr. B-o-B wrote:
>> On 10/9/2011 1:51 AM, paris2venice cried from the depths of the abyss:
>>> 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?
>>>
>>> Would it be something like this? Is this how you do it?
>>>
>>> <?
>>> php require_once './css.php'; /* css.php contains
>>> doctype, meta& css needed universally */
>>> ?>
>>>
>>> <!-- link href= calls to CSS needed on local page only -->
>>>
>>> <?
>>> php require_once './js.php'; /* js.php contains
>>> javascript calls needed universally */
>>> ?>
>>>
>>> <!-- script type="text/javascript" calls to Javascript needed on
>>> local page only -->
>>> </head>
>>
>> As Jerry mentioned separate DOCTYPE from your CSS for starter. Mixing
>> nonrelated things just leads to a clusterf*ck down the road. Keep it
>> seperate/keep it clean. It's worth it in the long run.
>>
>> An easy way to pull this off is to put all your javascripts and css into
>> a header type file like so (each CSS & JS seperately):
>>
>> if (@isset $javascript01){
>> put code here
>> }
>>
>> if (@isset $javascript02){
>> put code here
>> }
>>
>> if (@isset $css01){
>> put code here
>> }
>> etc....
>>
>> On your pages include the header file. Then on the pages/files you need
>> to use the $javascript01 & or $css01, just set the variable name you
>> created in the header file:
>>
>> $javascript01 = 1
>>
>> Just that easy.
>>
>
> There are a number of reasons you wouldn't want to do it this way - but
> all are off topic in a PHP newsgroups.
>

If the reasons are about how to use PHP, they are ON topic, in a PHP
newsgroup. (not newsgroup*s*)

--
Luuk
Re: including CSS & JS on only pages that need that CSS & JS [message #175573 is a reply to message #175572] Sun, 09 October 2011 19:08 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 10/9/2011 2:03 PM, Luuk wrote:
> On 09-10-2011 19:52, Jerry Stuckle wrote:
>> On 10/9/2011 9:46 AM, Mr. B-o-B wrote:
>>> On 10/9/2011 1:51 AM, paris2venice cried from the depths of the abyss:
>>>> 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?
>>>>
>>>> Would it be something like this? Is this how you do it?
>>>>
>>>> <?
>>>> php require_once './css.php'; /* css.php contains
>>>> doctype, meta& css needed universally */
>>>> ?>
>>>>
>>>> <!-- link href= calls to CSS needed on local page only -->
>>>>
>>>> <?
>>>> php require_once './js.php'; /* js.php contains
>>>> javascript calls needed universally */
>>>> ?>
>>>>
>>>> <!-- script type="text/javascript" calls to Javascript needed on
>>>> local page only -->
>>>> </head>
>>>
>>> As Jerry mentioned separate DOCTYPE from your CSS for starter. Mixing
>>> nonrelated things just leads to a clusterf*ck down the road. Keep it
>>> seperate/keep it clean. It's worth it in the long run.
>>>
>>> An easy way to pull this off is to put all your javascripts and css into
>>> a header type file like so (each CSS & JS seperately):
>>>
>>> if (@isset $javascript01){
>>> put code here
>>> }
>>>
>>> if (@isset $javascript02){
>>> put code here
>>> }
>>>
>>> if (@isset $css01){
>>> put code here
>>> }
>>> etc....
>>>
>>> On your pages include the header file. Then on the pages/files you need
>>> to use the $javascript01 & or $css01, just set the variable name you
>>> created in the header file:
>>>
>>> $javascript01 = 1
>>>
>>> Just that easy.
>>>
>>
>> There are a number of reasons you wouldn't want to do it this way - but
>> all are off topic in a PHP newsgroups.
>>
>
> If the reasons are about how to use PHP, they are ON topic, in a PHP
> newsgroup. (not newsgroup*s*)
>

The reasons have nothing to do with PHP - which is why I said they are
off topic. An HTML, CSS and/or Javascript newsgroups would be much better.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: including CSS & JS on only pages that need that CSS & JS [message #175576 is a reply to message #175565] Sun, 09 October 2011 20:31 Go to previous messageGo to next message
Michael Joel is currently offline  Michael Joel
Messages: 42
Registered: October 2011
Karma: 0
Member
On Sat, 8 Oct 2011 23:51:10 -0700 (PDT), paris2venice
<paris2venice(at)gmail(dot)com> 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?
>
> Would it be something like this? Is this how you do it?
>
> <?
> php require_once './css.php'; /* css.php contains
> doctype, meta & css needed universally */
> ?>
>
> <!-- link href= calls to CSS needed on local page only -->
>
> <?
> php require_once './js.php'; /* js.php contains
> javascript calls needed universally */
> ?>
>
> <!-- script type="text/javascript" calls to Javascript needed on
> local page only -->
> </head>
>
>
> Thanks a bunch for your help.


I think you are meaning you want to use PHP includes to drop in your
css and javascript. You can use the normal method combines with PHP or
just PHP...

Combined methode:

<link rel="stylesheet" type="text/css" href="GlobalCSS.css" />
<script type="text/javascript" src="GlobalJavascript.js"></script>
<?php

if($MYpageID="THIS IS THE PAGE I WANT IT ON") {
include("StylesForThisSpecialPage.php");
include("StylesForThisSpecialPage.php");
}
?>

The other method:

<?php
include("GlobalCSS.php");
include("Globalavascript.php");

if($MYpageID="THIS IS THE PAGE I WANT IT ON") {
include("StylesForThisSpecialPage.php");
include("SpecialJavascript.php");
}
?>

Of course the PHP files must be written just as they would be if they
were coded directly on the HTML page (not as if they are being
"linked").
Right or wrong? It works.

Mike
Re: including CSS & JS on only pages that need that CSS & JS [message #175577 is a reply to message #175576] Sun, 09 October 2011 23:54 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 10/9/2011 4:31 PM, Michael Joel wrote:
> On Sat, 8 Oct 2011 23:51:10 -0700 (PDT), paris2venice
> <paris2venice(at)gmail(dot)com> 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?
>>
>> Would it be something like this? Is this how you do it?
>>
>> <?
>> php require_once './css.php'; /* css.php contains
>> doctype, meta& css needed universally */
>> ?>
>>
>> <!-- link href= calls to CSS needed on local page only -->
>>
>> <?
>> php require_once './js.php'; /* js.php contains
>> javascript calls needed universally */
>> ?>
>>
>> <!-- script type="text/javascript" calls to Javascript needed on
>> local page only -->
>> </head>
>>
>>
>> Thanks a bunch for your help.
>
>
> I think you are meaning you want to use PHP includes to drop in your
> css and javascript. You can use the normal method combines with PHP or
> just PHP...
>
> Combined methode:
>
> <link rel="stylesheet" type="text/css" href="GlobalCSS.css" />
> <script type="text/javascript" src="GlobalJavascript.js"></script>
> <?php
>
> if($MYpageID="THIS IS THE PAGE I WANT IT ON") {
> include("StylesForThisSpecialPage.php");
> include("StylesForThisSpecialPage.php");
> }
> ?>
>
> The other method:
>
> <?php
> include("GlobalCSS.php");
> include("Globalavascript.php");
>
> if($MYpageID="THIS IS THE PAGE I WANT IT ON") {
> include("StylesForThisSpecialPage.php");
> include("SpecialJavascript.php");
> }
> ?>
>
> Of course the PHP files must be written just as they would be if they
> were coded directly on the HTML page (not as if they are being
> "linked").
> Right or wrong? It works.
>
> Mike

None of which are a good idea. And so those who keep espousing these
crappy solutions (which are off topic in this newsgroup but there are so
many of them I will respond anyway):

CSS files should be CSS files - and should not have a .php extension;
there is almost never a need for any php code in a css file. The same
with javascript and .js extensions.

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.

There are a lot of things "that work" but are not a good idea.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: including CSS & JS on only pages that need that CSS & JS [message #175578 is a reply to message #175577] Mon, 10 October 2011 00:03 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 10/9/2011 7:54 PM, Jerry Stuckle wrote:
>
> None of which are a good idea. And so those who keep espousing these
> crappy solutions (which are off topic in this newsgroup but there are so
> many of them I will respond anyway):
>
> CSS files should be CSS files - and should not have a .php extension;
> there is almost never a need for any php code in a css file. The same
> with javascript and .js extensions.
>
> 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.
>
> There are a lot of things "that work" but are not a good idea.
>

I should also add - unless the op has thousands of lines of javascript
or css unused on a page, these attempts will actually decrease
throughput. There is almost always more overhead in requesting another
file (css or javascript) than there is just getting the file once and
using it.

This whole question sounds like premature optimization - which is very bad.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: including CSS & JS on only pages that need that CSS & JS [message #175579 is a reply to message #175577] Mon, 10 October 2011 03:43 Go to previous messageGo to next message
Mr. B-o-B is currently offline  Mr. B-o-B
Messages: 42
Registered: April 2011
Karma: 0
Member
On 10/9/2011 6:54 PM, Jerry Stuckle cried from the depths of the abyss:

>
> None of which are a good idea. And so those who keep espousing these
> crappy solutions (which are off topic in this newsgroup but there are so
> many of them I will respond anyway):

So just ignore them then :)

> 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.
Re: including CSS & JS on only pages that need that CSS & JS [message #175585 is a reply to message #175569] Mon, 10 October 2011 09:22 Go to previous messageGo to next message
paris2venice is currently offline  paris2venice
Messages: 9
Registered: October 2011
Karma: 0
Junior Member
On Oct 9, 5:34 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 10/9/2011 2:51 AM, 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?
>
>> Would it be something like this?  Is this how you do it?
>
>> <?
>>     php require_once './css.php';             /* css.php contains
>> doctype, meta&  css needed universally */
>> ?>
>
>> <!--  link href= calls to CSS needed on local page only  -->
>
>> <?
>>     php require_once './js.php';                /* js.php contains
>> javascript calls needed universally */
>> ?>
>
>> <!--  script type="text/javascript" calls to Javascript needed on
>> local page only  -->
>> </head>
>
>> Thanks a bunch for your help.
>
> I'm not sure what you're trying to do here, but these aren't PHP
> questions.  You're only using PHP to include the files.
>
> You're asking basic layout file layout questions, which vary widely.
> The includes can be done in many ways.
>
> The first thing you need to do is learn about various ways to structure
> your files.  For instance, don't mix your DOCTYPE and other header
> information with CSS.
>
> I would suggest you start with a book on basic programming for the web,
> including html, css, etc.

Thanks for your reply.

I don't understand how you believe that I'm mixing my DOCTYPE and
other header info with CSS. What the server sends to the client
should be all that matters and that all arrives perfectly and has
never been a problem -- validator.w3.org doesn't have an issue with
it. I don't mind that you tell me there's some problem but how can I
know why there is a problem if it's not spelled out? That doesn't
mean I don't appreciate your help. I do.

My problem is just not being able to have something unique to a page
as I do it now. Thus, my post. If I posted this on an HTML or CSS or
JS newsgroup, they would go bananas, I guarantee it. I've read a huge
amount on php.net/manual -- it doesn't really answer questions like
this as best I can tell. And I'm not really a beginner -- just
nothing compared to what you guys know about PHP.
Re: including CSS & JS on only pages that need that CSS & JS [message #175586 is a reply to message #175585] Mon, 10 October 2011 12:27 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 10/10/2011 5:22 AM, paris2venice wrote:
> On Oct 9, 5:34 am, Jerry Stuckle<jstuck...@attglobal.net> wrote:
>> On 10/9/2011 2:51 AM, 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?
>>
>>> Would it be something like this? Is this how you do it?
>>
>>> <?
>>> php require_once './css.php'; /* css.php contains
>>> doctype, meta& css needed universally */
>>> ?>
>>
>>> <!-- link href= calls to CSS needed on local page only -->
>>
>>> <?
>>> php require_once './js.php'; /* js.php contains
>>> javascript calls needed universally */
>>> ?>
>>
>>> <!-- script type="text/javascript" calls to Javascript needed on
>>> local page only -->
>>> </head>
>>
>>> Thanks a bunch for your help.
>>
>> I'm not sure what you're trying to do here, but these aren't PHP
>> questions. You're only using PHP to include the files.
>>
>> You're asking basic layout file layout questions, which vary widely.
>> The includes can be done in many ways.
>>
>> The first thing you need to do is learn about various ways to structure
>> your files. For instance, don't mix your DOCTYPE and other header
>> information with CSS.
>>
>> I would suggest you start with a book on basic programming for the web,
>> including html, css, etc.
>
> Thanks for your reply.
>
> I don't understand how you believe that I'm mixing my DOCTYPE and
> other header info with CSS. What the server sends to the client
> should be all that matters and that all arrives perfectly and has
> never been a problem -- validator.w3.org doesn't have an issue with
> it. I don't mind that you tell me there's some problem but how can I
> know why there is a problem if it's not spelled out? That doesn't
> mean I don't appreciate your help. I do.
>

You said:

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

You are mixing your DOCTYPE and other header information with CSS. Not
a good idea.

As for validating - you could have your entire PHP file be include()
calls, each one including a different file containing one line of PHP or
HTML code. The final product will validate. But that doesn't mean it's
a good idea.

> My problem is just not being able to have something unique to a page
> as I do it now. Thus, my post. If I posted this on an HTML or CSS or
> JS newsgroup, they would go bananas, I guarantee it. I've read a huge
> amount on php.net/manual -- it doesn't really answer questions like
> this as best I can tell. And I'm not really a beginner -- just
> nothing compared to what you guys know about PHP.
>
>

This has nothing to do with PHP. Your problem is a lack of
understanding on how to correctly structure your pages. You could have
exactly the same problems if you were using Perl, Python, Ruby on Rails
or even SSI.

That's why I'm suggesting you start with HTML, CSS and Javascript
newsgroups. You need to learn how to properly structure your pages.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: including CSS & JS on only pages that need that CSS & JS [message #175587 is a reply to message #175579] Mon, 10 October 2011 12:30 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 10/9/2011 11:43 PM, Mr. B-o-B wrote:
> On 10/9/2011 6:54 PM, Jerry Stuckle cried from the depths of the abyss:
>
>>
>> None of which are a good idea. And so those who keep espousing these
>> crappy solutions (which are off topic in this newsgroup but there are so
>> many of them I will respond anyway):
>
> So just ignore them then :)
>

And spread crappy solutions like you continually provide? No, I'm here
to HELP people - not let them get your crappy advice.

>> 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.
>
>

To quote you:

----if (@isset $javascript01){
put code here
}

if (@isset $javascript02){
put code here
}

if (@isset $css01){
put code here
}
etc....

----

Crappy advice.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: including CSS & JS on only pages that need that CSS & JS [message #175591 is a reply to message #175587] Mon, 10 October 2011 17:04 Go to previous messageGo to next message
Michael Joel is currently offline  Michael Joel
Messages: 42
Registered: October 2011
Karma: 0
Member
On Mon, 10 Oct 2011 08:30:15 -0400, Jerry Stuckle
<jstucklex(at)attglobal(dot)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
Re: including CSS & JS on only pages that need that CSS & JS [message #175594 is a reply to message #175591] Mon, 10 October 2011 17:44 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 10/10/2011 1:04 PM, Michael Joel wrote:
> On Mon, 10 Oct 2011 08:30:15 -0400, Jerry Stuckle
> <jstucklex(at)attglobal(dot)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

You can also arm wrestle a polar bear. It's perfectly legal. But I
wouldn't recommend it.

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.

No, I don't have a problem with manners. I do have a problem with
people who suggest crappy code.

And BTW - I use includes a lot, also. But I use them correctly.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: including CSS & JS on only pages that need that CSS & JS [message #175595 is a reply to message #175591] Mon, 10 October 2011 18:34 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
Michael Joel wrote:
> On Mon, 10 Oct 2011 08:30:15 -0400, Jerry Stuckle
> <jstucklex(at)attglobal(dot)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(at)att(dot)net


My life has improved immensely after these simple steps.
Re: including CSS & JS on only pages that need that CSS & JS [message #175596 is a reply to message #175595] Mon, 10 October 2011 19:16 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
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(at)attglobal(dot)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(at)att(dot)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(at)attglobal(dot)net
==================
Re: including CSS & JS on only pages that need that CSS & JS [message #175597 is a reply to message #175579] Mon, 10 October 2011 21:17 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
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.)
Re: including CSS & JS on only pages that need that CSS & JS [message #175598 is a reply to message #175597] Mon, 10 October 2011 21:36 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
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(at)attglobal(dot)net
==================
Re: including CSS & JS on only pages that need that CSS & JS [message #175599 is a reply to message #175594] Tue, 11 October 2011 02:35 Go to previous messageGo to next message
Mr. B-o-B is currently offline  Mr. B-o-B
Messages: 42
Registered: April 2011
Karma: 0
Member
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?

>
> No, I don't have a problem with manners. I do have a problem with people
> who suggest crappy code.

Unless you consider this useful.
Re: including CSS & JS on only pages that need that CSS & JS [message #175601 is a reply to message #175599] Tue, 11 October 2011 03:04 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
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.

>>
>> No, I don't have a problem with manners. I do have a problem with people
>> who suggest crappy code.
>
> Unless you consider this useful.

I surely don't consider YOU useful. You're just a run-of-the-mill troll.

BTW - you know all about meds, don't you? Been on them all your life?


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: including CSS & JS on only pages that need that CSS & JS [message #175603 is a reply to message #175601] Tue, 11 October 2011 03:14 Go to previous messageGo to next message
Mr. B-o-B is currently offline  Mr. B-o-B
Messages: 42
Registered: April 2011
Karma: 0
Member
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.

>>>
>>> No, I don't have a problem with manners. I do have a problem with people
>>> who suggest crappy code.
>>
>> Unless you consider this useful.
>
> I surely don't consider YOU useful. You're just a run-of-the-mill troll.

Pot. Kettle. Black.

>
> BTW - you know all about meds, don't you? Been on them all your life?
>
Re: including CSS & JS on only pages that need that CSS & JS [message #175604 is a reply to message #175603] Tue, 11 October 2011 03:24 Go to previous messageGo to next message
Michael Joel is currently offline  Michael Joel
Messages: 42
Registered: October 2011
Karma: 0
Member
On Mon, 10 Oct 2011 22:14:10 -0500, "Mr. B-o-B" <wtf(dot)chuck(at)gmail(dot)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:
>>

I REALLY hope you both are very very young?
Re: including CSS & JS on only pages that need that CSS & JS [message #175607 is a reply to message #175565] Tue, 11 October 2011 09:09 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
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
Re: including CSS & JS on only pages that need that CSS & JS [message #175608 is a reply to message #175603] Tue, 11 October 2011 09:33 Go to previous messageGo to next message
Tim Streater is currently offline  Tim Streater
Messages: 328
Registered: September 2010
Karma: 0
Senior Member
In article <RyOkq.4249$%m(dot)1042(at)newsfe05(dot)iad>,
"Mr. B-o-B" <wtf(dot)chuck(at)gmail(dot)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?

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
Re: including CSS & JS on only pages that need that CSS & JS [message #175610 is a reply to message #175608] Tue, 11 October 2011 10:29 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
Tim Streater wrote:
> In article <RyOkq.4249$%m(dot)1042(at)newsfe05(dot)iad>,
> "Mr. B-o-B" <wtf(dot)chuck(at)gmail(dot)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."
Re: including CSS & JS on only pages that need that CSS & JS [message #175611 is a reply to message #175610] Tue, 11 October 2011 11:00 Go to previous messageGo to next message
Tim Streater is currently offline  Tim Streater
Messages: 328
Registered: September 2010
Karma: 0
Senior Member
In article <j715q6$2og$2(at)news(dot)albasani(dot)net>,
The Natural Philosopher <tnp(at)invalid(dot)invalid> wrote:

> Tim Streater wrote:
>> In article <RyOkq.4249$%m(dot)1042(at)newsfe05(dot)iad>,
>> "Mr. B-o-B" <wtf(dot)chuck(at)gmail(dot)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
Re: including CSS & JS on only pages that need that CSS & JS [message #175613 is a reply to message #175607] Tue, 11 October 2011 12:11 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
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.)
Re: including CSS & JS on only pages that need that CSS & JS [message #175614 is a reply to message #175607] Tue, 11 October 2011 13:08 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
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(at)attglobal(dot)net
==================
Re: including CSS & JS on only pages that need that CSS & JS [message #175615 is a reply to message #175614] Tue, 11 October 2011 13:29 Go to previous messageGo to next message
Beauregard T. Shagnas is currently offline  Beauregard T. Shagnas
Messages: 154
Registered: September 2010
Karma: 0
Senior Member
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
Re: including CSS & JS on only pages that need that CSS & JS [message #175617 is a reply to message #175615] Tue, 11 October 2011 17:14 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
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(at)attglobal(dot)net
==================
Re: including CSS & JS on only pages that need that CSS & JS [message #175618 is a reply to message #175614] Tue, 11 October 2011 19:14 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
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
Re: including CSS & JS on only pages that need that CSS & JS [message #175619 is a reply to message #175618] Tue, 11 October 2011 20:38 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
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.)
Re: including CSS & JS on only pages that need that CSS & JS [message #175620 is a reply to message #175614] Wed, 12 October 2011 00:48 Go to previous messageGo to next message
paris2venice is currently offline  paris2venice
Messages: 9
Registered: October 2011
Karma: 0
Junior Member
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.
Re: including CSS & JS on only pages that need that CSS & JS [message #175621 is a reply to message #175620] Wed, 12 October 2011 01:51 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
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(at)attglobal(dot)net
==================
Re: including CSS & JS on only pages that need that CSS & JS [message #175622 is a reply to message #175620] Wed, 12 October 2011 03:11 Go to previous messageGo to next message
Hans Olo is currently offline  Hans Olo
Messages: 7
Registered: October 2011
Karma: 0
Junior Member
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.
Re: including CSS & JS on only pages that need that CSS & JS [message #175623 is a reply to message #175621] Wed, 12 October 2011 05:03 Go to previous messageGo to next message
paris2venice is currently offline  paris2venice
Messages: 9
Registered: October 2011
Karma: 0
Junior Member
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.
Re: including CSS & JS on only pages that need that CSS & JS [message #175624 is a reply to message #175623] Wed, 12 October 2011 10:19 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
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(at)attglobal(dot)net
==================
Re: including CSS & JS on only pages that need that CSS & JS [message #175625 is a reply to message #175622] Wed, 12 October 2011 10:20 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
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(at)attglobal(dot)net
==================
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: .htaccess vs PHP header(location:)
Next Topic: How to redirect user based on user country?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 15:22:11 GMT 2024

Total time taken to generate the page: 0.03425 seconds