如果我需要做更多事情来提高网络应用程序的性能,需要一些想法和建议
我正在开发一个使用大量ajax来显示数据的网络应用程序,我想知道我是否可以获得任何关于我可以做些什么来加速应用程序并减少带宽等的建议。
我正在使用php 、mysql、freeBSD、Apache、Tomcat 适合我的环境。我拥有服务器并且可以完全访问所有配置文件等。
我在 apache http.conf 文件中打开了 gzip deflate 压缩。我已经混淆并缩小了所有 .js 和 .css 文件。
我的网络应用程序以这种一般方式工作。登录后,用户登陆index.php页面。索引页面上的所有链接都是 ajax 调用来读取 .php 类函数,该函数将检索字符串中的 html 并将其显示在主 index.php 页面上某处的 div 内。
大多数返回 html 的函数都返回如下字符串:
<table>
<tr>
<td>Data here</td>
</tr>
</table>
我不返回完整的“”内容,因为它已经存在于主 index.php 页面中。
然而,返回的html字符串被格式化为制表符、空格、注释等,以便于阅读代码。我应该花时间缩小这些页面并删除选项卡、评论、空格吗?或者缩小 .php 页面是否可以忽略不计,因为它在服务器上?
我想我想弄清楚我构建 web 应用程序的方式是否会导致带宽问题,如果我可以减少 .php 类文件的大小,我是否可以通过减少它们来提高一些性能。大多数 .php 类大小为 40-50KB,最大为 99KB。
为了速度,我考虑过使用内存缓存,但真的不知道事后添加它是否值得,而且我不太知道如何实现它。我不知道服务器上是否打开了任何缓存...我想我已将其留给浏览器...我不太熟悉缓存领域。
现在该网站看起来并不慢,但我是唯一的用户......我只是想知道它是否值得付出额外的努力。
任何建议或文章将不胜感激。
提前致谢。
I'm working on a webapp that uses a lot of ajax to display data and I'm wondering if I could get any advice on what else I could do to speed up the app, and reduce bandwidth, etc.
I'm using php, mysql, freeBSD, Apache, Tomcat for my environment. I own the server and have full access to all config files, etc.
I have gzip deflate compression turned on in the apache http.conf file. I have obfuscated and minified all the .js and .css files.
My webapp works in this general manner. After login the user lands on the index.php page. All links on the index page are ajax calls to read a .php class function that will retrieve the html in a string and display it inside a div somewhere on the main index.php page.
Most of the functions returning the html are returning strings like:
<table>
<tr>
<td>Data here</td>
</tr>
</table>
I don't return the full "<html><head>
" stuff, because it already exists in the main index.php page.
However, the html strings returned are formatted with tabs, spaces, comments, etc. for easy reading of the code. Should I take the time to minify these pages and remove the tabs, comments, spaces? Or is it negligible to minify the .php pages because its on the server?
I guess I'm trying to figure out if the way I've structured the webapp is going to cause bandwidth issues and if I can reduce the .php class file size could I improve some performance by reducing them. Most of the .php classes are 40-50KB with the largest being 99KB.
For speed, I have thought about using memcache, but don't really know if adding it after the fact is worth it and I don't quite know how to implement it. I don't know if there is any caching turned on on the server...I guess I have left that up to the browser...I'm not very well versed in the caching arena.
Right now the site doesn't appear slow, but I'm the only user...I'm just wondering if its worth the extra effort.
Any advice, or articles would be appreciated.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的建议是不要通过 AJAX 调用发送 HTML。相反,通过 JSON 仅发送底层数据(“此处的数据”部分),然后通过客户端函数处理该数据,该函数将使用正确的 HTML 对其进行修饰,然后将其注入 DOM。这将大大加快 Ajax 调用的速度。
My recommendation would be to NOT send the HTML over the AJAX calls. Instead, send just the underlying data ("Data here" part) through JSON, then process that data through a client-side function that would decorate it with the right HTML, then injecting it into the DOM. This will drastically speed up the Ajax calls.
Memcache 提供了一个允许您缓存数据的 API。您还需要(在我看来更重要的是)关于缓存什么以及何时使缓存无效的策略。这不能通过查看源代码来确定,它来自于您的网站的使用方式。
然而,可以立即使用操作码缓存(例如APC)。
Memcache provides an API that allows you to cache data. What you additionally need (and in my opinion more important is) is a strategy about what to cache and when to invalidate the cache. This cannot be determined by looking at the source code, it comes from how your site is used.
However, an opcode cache (e.g. APC) could be used right away.
代码美化器是给人类用的,不是给机器用的。
作为优化的一部分,您应该起飞。
或者简单地在您的应用程序中添加一个标志检查,某些条件匹配(如调试模式),它会返回格式良好的 JavaScript。否则,空白对机器来说没有任何意义。
APC
您应该始终使用 APC 来编译和使用 APC。将 php 脚本缓存到操作码中。
为什么?
>有什么好处?
Memcache - 不行吗?
取决于,如果您处于单主机环境中,可能不会获得任何更好的效果。 memcache最大的优点是信息共享和存储。分布(这意味着多服务器环境,缓存一次,使用多次)。
等等?
Code beautifier is for human not for machine.
As part of the optimization you should take off.
Or simply add a flag checking in your application, certain condition match (like debug mode), it return nicely formatted javascript. Otherwise, whitespace does not mean anything to machine.
APC
You should always use APC to compile & cache php script into op-code.
Why?
What are the benefits?
Memcache - NO GO?
depends, if you are in single host environment, probably not gain any better. The biggest advantages of memcache is for information sharing & distribution (which mean multiple server environment, cache once and use many).
etc?