且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何通过PHP脚本加载图像缓存

更新时间:2023-12-05 17:41:52

为什么不让 getRandomImage 成为PHP函数,它返回图像的路径。您可以使用已填写的随机图像路径渲染页面。

Why not have getRandomImage be a PHP function, which returns a path to the image. You can render the page out with the random image paths already filled in.

<img src="<? echo getRandomImage() ?>">

然后你可以使用真正的缓存标题实际提供你的图像,你的带宽也不会受到如此严重的打击。

Then you can actually serve your images with real cache headers, and your bandwidth wont be getting hammered so hard.

在页面渲染时在服务器端执行此操作,而不是在之后。之后做更多的工作,正如你所发现的那样,也更复杂。

Do this on the server side while the page is rendering, not after. Doing it after is more work and, as you are finding out, is more complicated too.