including CSS & JS on only pages that need that CSS & JS [message #175565] |
Sun, 09 October 2011 02:51 |
|
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 #175570 is a reply to message #175565] |
Sun, 09 October 2011 09:46 |
|
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 #175576 is a reply to message #175565] |
Sun, 09 October 2011 16:31 |
|
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 #175579 is a reply to message #175577] |
Sun, 09 October 2011 23:43 |
|
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 05:22 |
|
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 #175591 is a reply to message #175587] |
Mon, 10 October 2011 13:04 |
|
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 #175595 is a reply to message #175591] |
Mon, 10 October 2011 14:34 |
|
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 #175597 is a reply to message #175579] |
Mon, 10 October 2011 17:17 |
|
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 #175599 is a reply to message #175594] |
Mon, 10 October 2011 22:35 |
|
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 #175603 is a reply to message #175601] |
Mon, 10 October 2011 23:14 |
|
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 #175607 is a reply to message #175565] |
Tue, 11 October 2011 05:09 |
|
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 05:33 |
Tim Streater
Messages: 328 Registered: September 2010
Karma: 0
|
Senior Member |
add to buddy list ignore all messages by this user
|
|
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 06:29 |
|
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 07:00 |
Tim Streater
Messages: 328 Registered: September 2010
Karma: 0
|
Senior Member |
add to buddy list ignore all messages by this user
|
|
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 08:11 |
|
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 #175615 is a reply to message #175614] |
Tue, 11 October 2011 09:29 |
|
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 #175618 is a reply to message #175614] |
Tue, 11 October 2011 15:14 |
|
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 #175620 is a reply to message #175614] |
Tue, 11 October 2011 20:48 |
|
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 #175622 is a reply to message #175620] |
Tue, 11 October 2011 23:11 |
Hans Olo
Messages: 7 Registered: October 2011
Karma: 0
|
Junior Member |
add to buddy list ignore all messages by this user
|
|
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 01:03 |
|
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.
|
|
|
|
|