web页面渲染是采用php渲染好,还是采用ajax方式渲染好?
现在公司的管理后台页面基本上ajax来渲染页面,把js禁用掉整个页面就废了,页面的接口太多,比方一个分页功能都是js全部渲染出来的,我觉得php与ajax 混合使用是最好的, 各位大牛提提意见呗。
回复内容:
1、到今天,几乎没人会禁掉js。2、php生成全部代码,肯定比只生成框架,然后ajax要快。原因是,两种情况下,你的网线传输的数据K数基本是一样的,如果js执行innerHTML的话,会修改dom,造成重绘和重排,代价比较大。即使php只负责框子,但一般php项目都是使用了模板引擎的,即使提供框子也需要动用模板引擎,那么模板引擎处理框子和处理全部内容,是几乎感觉不出时间区别的。如果数据量大,那么ajax的优势是可以分段下载数据,这样就显得比php快。
3、忽略php比ajax快这种情况,它们的区别就是看使用场合,而且没有必须的规则,所以不要太较真。
ajax永远是跟“安全”的“频繁更新”的“格式的批量数据”以及“数据缓存”相关,而且用户没有欲望看旧的数据,也就是说,用户没兴趣、没必要点后退键,看老数据。因为ajax默认不支持后退键,如果想实现后退,需要做大量的工作。
也就是说:
A、如果抓的数据是敏感的,那么不要ajax,不敏感的话就可以ajax。如果抓的不是格式的批量数据,而是别的东西,比如抓了一条视频地址,即然只有一条,没必要ajax。如果预判用户会查阅大量的数据,那么用ajax先抓一批数据(或者首批数据用php输出),然后后台慢慢悠悠的再继续抓其他数据,然后缓存起来,这时候用ajax。
B、如果你的页面呈现完毕之后处于数据静止状态(不进行数据频繁更新),那就肯定是用php。(如果页面显示了当天日期,昨天是15日,今天是16日,也认为是数据静止。如果在某个位置显示了你的用户名,也认为是数据静止。)
C、如果你的页面呈现完毕之后不处于数据静止状态,也就是说在你观看页面的几十秒期间内,服务器数据库就有了大批量的数据更新,而且你有必要马上看到这些更新,那么就用ajax。或者说你的页面打开之后可能需要保持半小时、一小时不关闭,而且要随时看到数据更新,那肯定要用ajax。
从上述我的理论来讲,笼统说,你的公司内部网站,大量利用php,加上一丢丢的ajax,就对了。
关于分页,有人说用ajax来获取分页信息,岂不是美哉?这里道理其实是一样的,列表可以视为格式的批量数据,而且缓存有利于翻页,所以可以ajax。但是有可能列表页更新很慢,几天几周才新增一条,那又可以考虑php。所以这次就看情况而定。
如果一个网页展示了不算多的三四十条批量数据,今天是这些数据,明天仍是这些数据,没变过,这时候尽管符合“格式的批量数据”,但也推荐php,不推荐ajax。所以我才说,公司内网,可以大量用php。
对于php生成了html的情况,那就跟php无关了,如果一个html页面内的数据总要更新,当然ajax,没疑问。 公司这么做是有原因的 以后做 手机端 ios android 后台不用变 不用做兼容 现在这几个回答的都不知道是什么鬼…
题主说了是管理系统啊,很明显就是内部使用的。
这种应用特点就是交互暴多,访问速度并不重要,开发投入资源偏少。这种情况下用偏前端的架构(angular,vue,react……),很明显在这个场景下,这就是最优解,这样开发效率更高,维护更舒服
如果这种应用用php直出吐页面,再加jquery,jquerytable什么的做交互。维护起来你会想死的,不说别的,新增一个管理面板就得赫呲赫呲的写成百上千行的js 用ajax渲染页面,我这边称为是云端结构的web架构。因为现在做移动端开发的项目占了主要市场(如微信微网站开发),不用考虑SEO的情况下,云端结构要比混合渲染要好。这个好主要源于软件工程开发要点的三个方面:灵活性、拓展性和重用性。
1、重用性。如果是用混合渲染,前端很少使用框架,使用也只是类似bootstrap这样的CSS框架,难以构建JS的底层架构。这样就极大的限制了前端的重用性。
2、灵活性。云端结构的开发,前端技术员可以完全独立出来构建页面,后端技术员只需要按照需求提供必要的接口就可以了。
3、扩展性。构建好一个好的前端底层,迭代新功能新页面非常方便。 如果你只是一个简单的页面,PHP直接来比较简单。但有一种情况:页面内容较多的长页面;并发量较大。
那么,PHP渲染结构,ajax渲染细节,就体现出威力了。这样可以更快地响应客户端(服务器处理的逻辑少了),用户能更快地看到东西,而不是浏览器转圈圈。
之后的ajax,也只是数据传递,渲染结构还是在浏览器,服务器少了很多字符串的操作,必然比一次性在服务端渲染要好。
更甚至说,你可以把每个区域的请求分发到不同的业务系统,做好跨域就行了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
