开发者

Opinions on possible optimization for a web application using javascript

开发者 https://www.devze.com 2023-01-21 07:11 出处:网络
I\'m thinking of implementing my web application in a certain way as an optimization, and I\'d like to get people\'s opinions on whether this is a good idea or not.

I'm thinking of implementing my web application in a certain way as an optimization, and I'd like to get people's opinions on whether this is a good idea or not.

Here's the details: For most of my pages, instead of determining server side whether the user is logged in, and then modifying the page I send based on that, I want to send the same page to everyone, this way I can make use of my reverse caching proxy and for most requests not even have to run any dynamic code at all.

The differences that need to be done for logged in users will be done in javascript. The necessary information to make the changes (开发者_Go百科what their user name is, their user id, and if they are logged in or not) will be stored in a cookie that can be read by javascript.

I don't need to worry about the users not having javascript because my web app requires javascript to be used anyways.

Only the most popular pages that are accessible to both logged in and logged out users will do this.

What do you guys think? Pros/cons? Is this something that websites commonly do?


Doing it for 100% of your application would be a little problematic, however, it sounds like you are seeking to use something called the Model-View-Presenter pattern:

http://en.wikipedia.org/wiki/Model_View_Presenter

Be wary that, when using javascript, your code is exposed, meaning that any security measure taken is potentially hackable through the browser. Add protection on the server side and you are set.

Also, since you are going to rely heavily on javascript, I really recommend you using Mootools, which is an object-oriented approach to javascript. That way you can keep your code really modular, work around messy implementations using custom and class events, etc.


Major con: If you are determining what content a viewer can access with JavaScript alone, it stands to reason that a malicious user can potentially access premium content with just a little glance at your source code.


I'm not sure what you are optimizing really - you need to fetch the user data anyway, and only the server has that. Do you plan on sending an AJAX request requesting for data and using javascript to format it? you are only saving on output generation which is usually not the bottleneck in web application. Much more often the database / IO (files) / network (HTTP requests) are the bottlenecks.

The major con here is that by moving all output generation to javascript, you will increase substantially the download size and reduce overall responsiveness. Since none of the big sites use this approach, you can be sure it doesn't solve scalability problems.

0

精彩评论

暂无评论...
验证码 换一张
取 消