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

  • Home
  • SEARCH
  • 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 6105827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:00:47+00:00 2026-05-23T14:00:47+00:00

I’m working on a php/codeigniter project and I’m thinking about creating a controller specifically

  • 0

I’m working on a php/codeigniter project and I’m thinking about creating a controller specifically to handle returning customized css & javascript files.

In previous projects I’ve included external CSS & JS files in the headers of my view files but they’ve essentially had to be static since they were just sent as regular assets by the server. For my next project I’m thinking about using a controller and essentially making my CSS/Javascript files ‘views’ that are loaded by the controller.

What do you guys think? Is this a good approach? Is there a generally accepted better way of doing this?

  • 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-05-23T14:00:48+00:00Added an answer on May 23, 2026 at 2:00 pm

    By using a controller for your js/css, you have the overhead of loading a ton of unnecessary stuff for every request for the file. The security class, the input class, the router, exceptions, etc.

    You don’t need any of this for what should be static content. You don’t want the files to be dynamic either (changing per request) because this will affect the browser cache. Either the file will get cached in the state it was loaded, or you will lose the benefit of the browser cache.

    Your best bet is to combine the files, minimize them, and write the content to a static file, but then they aren’t dynamic. However, they probably shouldn’t be.

    Another thing you can do is to use a php file to combine the static files and reference it in your <link> tag (screen.php). Simple CSS example:

    <?php
    header('Content-type: text/css');
    $files = array(
        'css/reset.css',
        'css/screen.css',
        'css/typography.css',
    );
    foreach ($files as $file)
    {
        readfile($file);
    }
    

    Either way, you should update the file name, perhaps with a query string, in order to avoid the old cached file being served. Example: /screen.css?version=2

    I do use $this->load->view() sometimes for dynamic js, but only for inline script tags (dynamic WYSIWYG configuration for example). This allows you to pass variables to the “view” file as well as avoid cache issues.

    My point of view is that it’s not worth firing up CI and all the related dependencies just to serve what should be static content.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm trying to create an if statement in PHP that prevents a single post
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I would like to count the length of a string with PHP. The string

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.