如何缓存我网站上的脚本和图像?

发布于 2024-11-02 19:44:32 字数 557 浏览 3 评论 0原文


问题 ::::::


我一直在尝试创建一个网站(托管在 x10hosting 上)。所以我一直在寻找如何建立一个快速的网站。我得到了一个改进 Jquery 代码的页面。以下是该页面的链接。 在该页面中,我读到包含来自 Google.com 的 Jquery 框架代码可以加快网站速度。我也找到了原因,因为Google.com缓存了Jquery框架代码,这样用户就不必一次又一次下载Jquery框架代码。所以我想我的网站也可以这样做吗?嗯,我正在使用基于 Linux 的网站。因此,任何人都可以建议一个页面或代码来缓存我的网站中的脚本或图像,以便用户不必一次又一次下载它。


链接::::::


改进 JQuery


提前致谢!


Question ::::::


I have been trying to create a site (Hosted on x10hosting). So I have been searching how to build a fast site. And I got a page to improve Jquery codes. Below is the link to the page.
In that page I read that including Jquery framework codes from Google.com can speed up the site. And I also find out the cause to it, as the Google.com caches the Jquery framework code so that user doesn't have to download the Jquery framework code again and again. So I was thinking that can I do that too with my site. Well I'm using Linux based site. So can anyone suggest a page or a code to cache scripts or images in my site so that user doesn't have to download it again and again.


Links::::::


Improve JQuery


THANKS IN ADVANCE!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

北渚 2024-11-09 19:44:32

有可能,只要您使用普通的静态文件(以 .js.gif 等结尾),您的服务器就已经为您进行了缓存。

您可以使用 Firefox 中的 Firebug 等工具或 Chrome 中的内置开发人员控制台来查找。最简单的方法是右键单击一个元素,然后选择“检查元素”。

如果切换到“网络”选项卡,您将看到必须对当前文件发出的所有请求。

在此处输入图像描述

304 未修改(来自缓存)表示该资源没有再次加载。如果您看到静态资源,则说明已经存在一些缓存。主文档通常每次都会重新加载;谷歌分析和广告等跟踪代码也是如此。在大型网站上,您还会看到大量 200 OK 请求。

在该选项卡中,您还可以找到每个资源的响应标头。本教程可以帮助您解读每个标头的含义:针对 Web 作者和网站管理员的缓存教程

微调缓存是一个非常复杂的领域。 这里是一个有关在 Apache 上缓存图像的问题。 Stack Overflow 对此存在各种现有问题。

如果您想总体上提高网站速度,请查看以下问题:优化以减少网站加载时间

Chances are that as long as you use normal, static files (ending in .js, .gif and so on), your server already does caching for you.

You can find out using a tool like Firebug in Firefox, or the built-in developer console in Chrome. The easiest way to get there is by right-clicking an element, and choosing "Inspect element".

If you switch to the "Net" tab, you will see all the requests that had to be made for the current file.

enter image description here

304 not modified and (from cache) means that the resource was not loaded again. If you see those for static resources, there is some caching already in place. The main document usually gets reloaded every time; the same goes for tracking codes like Google Analytics, and Ads. On a big site, you will expect to see a number of 200 OK requests as well.

In the tab, you can also find out the response headers of each resource. This tutorial could help deciphering what each header means: Caching Tutorial for web authors and webmasters

Fine-tuning caching is a very complex field. Here is a question that deals with caching images on Apache. Stack Overflow has a variety of existing questions on this.

If you want to generally look into speeding up your site, check out this question: Optimizations to reduce website loading time

够运 2024-11-09 19:44:32

正如佩卡所说,微调缓存是一个非常复杂的领域。我建议从“高性能网站”这本书开始,然后按照雅虎性能博客

As pekka said fine tuning caching is a very complex field. I recommend beginning with the book "High Performance Web Sites" and follow yahoo performance blog.

夏尔 2024-11-09 19:44:32

对于收费网络主机来说,x10 相当不错,如果您的网站使用大型数据库,任何真正的速度问题都将与 MSQL 相关。

将所有 javascript (.js) 和 css 放入外部文件[托管在任何地方],以便它们可以缓存在访问者浏览器中以供重复使用,这是一个很好的起点。 (大多数人都知道图像缓存,但通常不知道 css 和 js 文件也会缓存)

另一个有用的技巧是 客户端包含,通常每次页面加载时都必须从服务器移动到访问者的 html 块也可以通过将 html 包装在 javascript 中而缓存在浏览器内文件。

As they go x10 is pretty good for a fee web host, any real speed issue is going to be with MSQL if your site uses a large database.

Getting all your javascript (.js)and css into external files [hosted wherever] so they can be cached inside the visitors browser for re-use is a good place start. (most people know that images cache, but are often unaware that css and js files cache also)

Another useful trick is that of Client Side Includes, whereby chunks of html that would normally have to be moved from the server to visitor every time the page loads can also cached inside the browser by wrapping the html inside a javascript file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文