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
Return to the default flat view Create a new topic Submit Reply
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 previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
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
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
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 20:36:39 GMT 2024

Total time taken to generate the page: 0.04501 seconds