为整个站点加载一次文件 [英] Load file once for whole site

查看:52
本文介绍了为整个站点加载一次文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我的每个网站页面都有一个include(''header.php'')行。是否可以加载此文件一次而不是每次到达新页面?由于它包含了一些css和动态生成的php,因此显着减慢了速度。


谢谢

解决方案

< blockquote>





我的每个网站页面都有一个include(''header.php'')行。是否可以加载此文件一次而不是每次到达新页面?因为它包含了一些css和即时生成的php,所以它显着减慢了速度。


谢谢



i相信对象可以使用_autoload函数自动加载到应用程序中,也不会保存状态,它会自动初始化对象,而不必手动初始化它们。


如果你休息要求预加载,css和js,我猜图像可以预加载,我从来没有读过任何像预加载css等,因为这是什么标头容器,每次请求发送到服务器,标头必须自动发送:)


我可能完全错了,但它只是一个建议,即使我想看看是否可以做到这一点..


**线程订阅**


欢呼!!



i相信对象可以自动加载到应用程序中_autoload功能,也没有保存相反,它会自动初始化对象,而不必手动初始化它们。


如果要求预加载,css和js,我会猜想图像可以预加载,我从来没有读过像预加载css等的东西,因为这是什么标头容器,每次请求发送到服务器时,标头都必须自动发送:)


我可能完全错了,但是它只是一个建议,即使我想看看是否可以做到这一点..


**线程订阅**


干杯!



让我成为第一个说出你完全错误的人。


__autoload()用于课程。 (不要和你一起去那里)


答案显而易见,根本就没有。


刷新(第一次或第一次加载每个页面)浏览器请求页面,PHP通过再次执行所有计算来构建页面。


使用分析器查看是否可以改进某些功能。向我们展示代码,那里可能有不必要的停顿/循环。


然而,使用CSS和Javascript,如果您包含相同的文件,浏览器将加载它更快。我不是CSS专家,但我听说过那种影响。


与图像相同。鉴于缓存已启用。


" Peace Out"


-Dan


我使用了包含(header.php)的类似设置,这就是我调用CSS的地方。让我向你保证,如果你这样做,你的CSS和图像只会被调用一次,除非你点击刷新,或者用户关闭了他们的缓存(不太可能)。

你的速度问题如果你有一个普通的服务器(提供商)并且你的代码不是非常低效,那么动态生成的php应该不会感觉到!

你有广告,谷歌分析等等你的东西吗?页?我有这个,经过一些测试后意识到他们占用了比我页面其余部分更多的时间(所以我暂时把它们都删除了)。

如果你发布你的代码,我们可以看看是什么'它的速度减慢了很多,但是有太多事情要猜测。


Hi,

I have an include(''header.php'') line in each of my site pages. Is it possible to load this file once instead of every time a new page is reached? It''s significantly slowing things down as it contains some css and on-the-fly generated php.

Thanks

解决方案

Hi,

I have an include(''header.php'') line in each of my site pages. Is it possible to load this file once instead of every time a new page is reached? It''s significantly slowing things down as it contains some css and on-the-fly generated php.

Thanks

i believe objects can be loaded automatically into the application using _autoload function, also it doesnt saves the state instead, it intializes the object automatically without having to intialize them manually..

rest if you are asking to preload, css and js, i guess images can be preloaded, i never read anything like preloading css etc, as this is what header container and everytime a request is sent to server, header has to be sent automatically :)

I may be completely wrong, but its just a suggestion, even i want to see if this can be done..

** Thread Subscribed **

cheers !!


i believe objects can be loaded automatically into the application using _autoload function, also it doesnt saves the state instead, it intializes the object automatically without having to intialize them manually..

rest if you are asking to preload, css and js, i guess images can be preloaded, i never read anything like preloading css etc, as this is what header container and everytime a request is sent to server, header has to be sent automatically :)

I may be completely wrong, but its just a suggestion, even i want to see if this can be done..

** Thread Subscribed **

cheers !!

Let me be the first to say your completely wrong.

__autoload() is used for classes. (Won''t go there with you two)

The answer is plainly and simply no.

Upon refresh (loading each page, first time or again) the browser requests the page, PHP builds the page by doing all the calculations again.

Use a profiler to see if you can improve some of your functions. Show us the code and there maybe unnecessary halts/loops in there.

With CSS and Javascript however, if you include the same file the browser will load it faster. I''m no CSS expert but i''ve heard something to that affect.

Same with images. Given that cacheing is on.

"Peace Out"

-Dan


I have use a similar set up with include(header.php) and that is where my CSS is called. Let me assure you, if you have done it like that your CSS and images will only be called once, unless you hit refresh, or the user has their cache turned off (unlikely).
Your speed problems with on-the-fly generated php should not be felt if you have a normal server (provider) and you code is not REALLY inefficient!
Do you have things like adverts, google analytics, etc on your page? I had that and after some testing realised they took up more time than the rest of my page (so I got rid of them all for now).
If you post your code we can maybe see what''s slowing it down so much, but there is too many things to just guess.


这篇关于为整个站点加载一次文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆