Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8252441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:34:02+00:00 2026-06-08T00:34:02+00:00

I would like to hide the unused js and css files from the php

  • 0

I would like to hide the unused js and css files from the php page.

Some of the js files are unused by some pages, so I would like to hide them. By hidding them I can make webpage faster and get good grade in pagetest.

I used simple php code to hide the code for one page. Works good, the file is hidden for that page, for other pages the code not works. It is displaying text instead of link , like a text in textarea..

<?php
    function curPageName() {
        return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
    }
    $currentp=curPageName();

    if($currentp=="main1.php"){
        echo "";
    } else { 
        //works 
        echo "<link type=\"text/css\" rel=\"stylesheet\" href=\"../rws.css\"     />"; 
        /// not works 
        echo "<link type=\"text/css\" rel=\"stylesheet\" href=\"http://img.y.com/rws.css\"     />"; 
    }
?>

The code works for /rws.css, if I use a http://url.com/rws.css it wont.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T00:34:05+00:00Added an answer on June 8, 2026 at 12:34 am

    Here an example :

    <?php
    
    function get_current_file_name () {
    $Exploded_Data = explode(‘/’, $_SERVER['PHP_SELF']); //explode the path to current file to array
    $Exploded_Data = array_reverse ($Exploded_Data); //reverse the arrays order cos php file name is always after last /
    $CurrentPage = $Exploded_Data[0]; // assign the php file name to the currentpage variable
    return $CurrentPage;
    }
    
    $CurrentPage = get_current_file_name ();
    
    if($CurrentPage!="main1.php"){
        echo('<link type="text/css" rel="stylesheet" href="style1.css" />'); 
    }
    else if$CurrentPage!="main2.php"){
        echo('<link type="text/css" rel="stylesheet" href="style2.css" />'); 
    }
    
    
    ?>
    

    You can use __FILE__ instead of $_SERVER['PHP_SELF']

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to hide some content from public (like google cached pages). Is
I would like to hide any text matching a pattern from any HTML page,
I would like to hide a page from search engine using meta tag. Is
I would like to hide some form elements and only show them when I
I have a webpart with asp.net control within. I would like to hide some
I have a 3-columns page where I would like to hide my right sidebar
I'm using jQuery UI 1.8 and I would like to hide the year from
I would like to hide the current page that the user is looking at
I would like to hide some part of content loaded via ajax, when the
I'm working on a rails app and would like to hide away some code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.