是否使用 echo base_url();调用 CSS、图像和 Javascript 文件会使网站变慢?
我正在使用 Codeigniter。我将图像、CSS 和 Javascript 文件保存在应用程序文档根目录中名为“support”的文件夹中。所以我的文档根文件夹看起来像这样 -
.settings
application
support
system
.buildpath
.project
index
.htacces
现在我的问题是它会让我的网站需要时间来加载,因为我必须使用 < 吗?每次我需要从支持文件夹中获取某些内容时,都会 echo base_url();?>support/
吗?因为你看到我什么时候使用 我实际上正在调用完整的网站地址..并且我有 7 个 CSS 和 13 个 javascript 文件要从“支持”调用,因此加载网站肯定需要时间。 (如果我错了,请纠正我)。如果您认为这样网站会变慢,您能告诉我到底应该将 CSS、图像和 javascript 文件放在哪里吗?我听说视图不是一个好地方。
提前致谢 :)
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-
.settings
application
support
system
.buildpath
.project
index
.htacces
Now my question is will it make my website take time to load as I have to use <? echo base_url();?>support/
every time I need to get something from my support folder? Because you see when I am using <? echo base_url();?>
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.
Thanks in Advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题可能比你想象的要大。
首先,使用
而不是“硬编码”您的网址不会减慢您的网站速度。像这样的函数调用对于加载页面的速度非常可以忽略不计。
我认为你问题的另一部分是关于架构的。
当您考虑网站的速度时,您需要知道哪些因素会减慢页面的加载速度。 (虽然不是一个详尽的列表,但这对您的情况会有帮助):
现在,在您的实例中,我建议将所有“静态”文件放在文件夹下的文档根目录中(例如
static< /代码>)。然后,使用
base_url()
函数在您的“视图”中访问它们。这样,您的页面在传递到浏览器时将对这些静态文件进行外部调用 - 允许浏览器缓存所有这些文件(假设标头设置正确)。如果您将它们放入视图中,那么它们实际上会添加到所请求的页面中。因此,请求的下一个页面必须与请求的第二页一起再次下载这些文件。有道理吗?
为了帮助减少“文件数量”,您可以随时连接并缩小您拥有的任何 css/javascript。因此,您可以使用所有代码为其提供 1 个 js 文件,而不是让浏览器下载并缓存 8 个 js 文件。
This question is probably bigger than you think.
First of all, using
<? echo base_url();?>
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):
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 thebase_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.