为了达到更好的用户体验,使用ajax来做数据的切换。假设,一页显示100个产品,产品有图片,有标题以及其他属性。用户点击一些条件,ajax重新加载一页数据。如何操作dom,让加载的过程看起来更柔和?这个词不知道用的对不对,最简单粗暴的就是,数据dom全清掉,通过ajax获取的json重新组织dom替换过去。更好的做法是怎样呢?
这个问题,大家的回答,已经很收益了。我在加大些范围,如何在用户体验与SEO之间平衡呢?我需要搜索引擎收录我的数据,但是这种AJAX的方式,搜索引擎又不认识?
回复内容:
为了达到更好的用户体验,使用ajax来做数据的切换。假设,一页显示100个产品,产品有图片,有标题以及其他属性。用户点击一些条件,ajax重新加载一页数据。如何操作dom,让加载的过程看起来更柔和?这个词不知道用的对不对,最简单粗暴的就是,数据dom全清掉,通过ajax获取的json重新组织dom替换过去。更好的做法是怎样呢?
这个问题,大家的回答,已经很收益了。我在加大些范围,如何在用户体验与SEO之间平衡呢?我需要搜索引擎收录我的数据,但是这种AJAX的方式,搜索引擎又不认识?
先说明点,清除dom和页面加载自然没有必然联系,不能说我操作了dom,我页面加载就不友好了。页面的友好性是通过交互实现。当然了,频繁大量的操作dom会带来性能问题,会延长页面的加载时间。
先说明下实现
要是我来做的话,会使用模板引擎如handlebars,拿到数据后渲染成html插入到dom中。如果使用了MVVM框架,只需要改变下model就可以了,但是大部分的框架还是如题主所说的粗暴方式处理的,angularjs除外。所以楼主不要纠结了,就得简单粗暴的干,关键是怎么粗暴的干,让人感觉不出来。
再说下效果
首先,在不同页切换时,加个loading的效果。
其次,使用模板引擎管理你的html
如果所有的产品不是一次性展示在页面上,使用图片懒加载
请求过的数据要缓存下来,避免再次请求
SEO
如果要做SEO的话,这种方式是不可行的,因为你的数据都是通过js去渲染的,搜索引擎爬取你的链接时,页面内容都是空的,那怎么收录你的产品链接?
刚咨询了我们的SEO工程师,国内搜索引擎还是以百度为主的,暂时还没办法执行js。为了SEO还是采用后端渲染的方式吧。
除非你们产品有这么吊,那就像它这样
你提的这个问题是不是想问通过什么样的交互才能感觉起来更好?其实这个关键靠你自己的想象了
可以这样,点击执行ajax的时候,把要替换的dom先用渐隐效果隐藏掉,然后弹出一个loading的提示,成功获取数据后,替换数据,然后loadding消失,dom显示
获取数据有时候会很快,所以,在替换完数据后,延迟一下再进行交互,大约300ms就够了
"柔和"主要靠的是交互细节,比如加载过程中的视觉反馈(进度条/菊花),加载过程中的交互(正在加载的时候做了其他操作怎么办?是mask蒙住,是中止之前的加载,还是操作无效并有视觉反馈“加载中请勿操作”?),以及加载时间过长时的反馈(类似gmail“加载比预期慢,是否切换到普通html版本” “仍在进行/重试”)等等

In PHP, you can use session_status() or session_id() to check whether the session has started. 1) Use the session_status() function. If PHP_SESSION_ACTIVE is returned, the session has been started. 2) Use the session_id() function, if a non-empty string is returned, the session has been started. Both methods can effectively check the session state, and choosing which method to use depends on the PHP version and personal preferences.

Sessionsarevitalinwebapplications,especiallyfore-commerceplatforms.Theymaintainuserdataacrossrequests,crucialforshoppingcarts,authentication,andpersonalization.InFlask,sessionscanbeimplementedusingsimplecodetomanageuserloginsanddatapersistence.

Managing concurrent session access in PHP can be done by the following methods: 1. Use the database to store session data, 2. Use Redis or Memcached, 3. Implement a session locking strategy. These methods help ensure data consistency and improve concurrency performance.

PHPsessionshaveseverallimitations:1)Storageconstraintscanleadtoperformanceissues;2)Securityvulnerabilitieslikesessionfixationattacksexist;3)Scalabilityischallengingduetoserver-specificstorage;4)Sessionexpirationmanagementcanbeproblematic;5)Datapersis

Load balancing affects session management, but can be resolved with session replication, session stickiness, and centralized session storage. 1. Session Replication Copy session data between servers. 2. Session stickiness directs user requests to the same server. 3. Centralized session storage uses independent servers such as Redis to store session data to ensure data sharing.

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

Alternatives to PHP sessions include Cookies, Token-based Authentication, Database-based Sessions, and Redis/Memcached. 1.Cookies manage sessions by storing data on the client, which is simple but low in security. 2.Token-based Authentication uses tokens to verify users, which is highly secure but requires additional logic. 3.Database-basedSessions stores data in the database, which has good scalability but may affect performance. 4. Redis/Memcached uses distributed cache to improve performance and scalability, but requires additional matching

Sessionhijacking refers to an attacker impersonating a user by obtaining the user's sessionID. Prevention methods include: 1) encrypting communication using HTTPS; 2) verifying the source of the sessionID; 3) using a secure sessionID generation algorithm; 4) regularly updating the sessionID.


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

SublimeText3 Linux new version
SublimeText3 Linux latest version

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1
Powerful PHP integrated development environment
