Does use of echo base_url(); to call CSS, images and Javascript files make a website slow?

I am using Codeigniter. I am keeping my images,CSS and Javascript files in a folder called "support" in the document root of my application. So my document root folder looks like this-


Now my question is will it make my website take time to load as I have to use support/ every time I need to get something from my support folder? Because you see when I am using I am actually calling the full website address.. and I have 7 CSS and 13 javascript files to call from "support" so it will definitely take time to load the website. (Please correct me if I am wrong). If you think by this a website can get slow could you please tell me where exactly should I put my CSS,images and javascript files in. I heard views is not a good place for this.

asked Apr 29, 2015 in codeinither by rahulgii
0 votes

1 Answer

0 votes

This question is probably bigger than you think.

First of all, using  instead of "hard-coding" your web address will not slow down your site. A function call like this is very negligible to the speed of loading your pages.

I think the other part of your question is regarding architecture.

When you think of speed for your website, you need to know what factors slow down the loading of your page. (Although not an exhaustive list, this will help in your case):

  1. the number of files (images, css, javascript, etc.) that need to load for your page
  2. the cache-ability of those files
  3. some server side header nonsense (e-tags and so-forth)
  4. the processing to build your php pages
  5. the size of your page

Now, in your instance, I would recommend putting all of your "static" files in the document root under a folder (say static). Then, access them all in your "views" with the base_url() function.

This way, your page as it's delivered to the browser, will make external calls for those static files - allowing the browser to cache all of those files (assuming the headers are set up correctly). If you put them into views, then they're actually added to the page that is being requested. So, the next page that is requested has to download those files again along with that second page being requested. Make sense?

To help with the "number of files", you can always concatenate and minify any css/javascript that you have. So instead of the browser downloading and caching 8 js files, you can serve it 1 js file with all of your code.

answered Apr 29, 2015 by rahulgii