iframe good or bad for my MVC web-app scenario

三世轮回 提交于 2019-12-07 07:16:26

TL;DR

Kindly let me know your thoughts - I don't want to know how good/bad iframes are, I just want to know what suits my requirements and if there's a better alternative to iframes .. for my scenario.

AJAX solves your client-server communication problems. There are plenty of client side libraries that make ajax very easy. For example Backbone integrates with a RESTful service right out of the box.

Alternatives to AJAX are COMET and WebSockets.

Thorough Reasoning

1.The page becomes v.light and fast because while the user is working on tab 1 the other tabs will be loading their iframe.

  • Iframes block onload of the main page

If you want to use onload handlers you have to wait for all iframes to load anyway.

The exact same concepts apply to loading HTML in order. I don't think HTML loading is a noticable bottleneck. I can't imagine getting a noticable speed increase from using iframes.

You may however get a noticable speed increase from using sensible HTML and lazy loading / pagination.

2.Functionally, each tab has to have its own Add/Edit and list independent. For example if I'm adding addresses then only my address iframe will be refreshed and the rest of the tabs/pages need not postback and reload the data.

Each tab should have it's own form instead that you can postback. If the user has JavaScript then you use ajax.

3.Having a universal save/cancel feature would require a v.complex in-memory caching of the object hierarchy if everything is in a single page(View). I can use user-controls (i.e. .ascx) but still processing everything in a single action is like huge & complex.

No. Use backbone/spine. Implement client side MVC and it's very simple and well structured.

4.I need not worry about SEO or bookmarks or dynamic dimensions. Instead I'm getting SOC (Separation of concerns), everything is being distributed v.well and the main thing is that it becomes extremely fast as the postbacks are separate.

Your still posting back rather then using ajax which is visually slower. Use proper HTML5 techiniques including client side MVC and it will distributed very well and extremely fast.

Disadvantages:

  • Cross iframe communication is a right pain.

It slows you down, and is a pain to develop. All your content in iframes are hard coupled together because they all relate to one customer.

How are you going to handle changing the customer in the main tab? Are you going to reload the other 3 iframes to re-populate it with the correct data?

That's very expensive and slow

  • Not semantic

Contexts in which this element can be used: Where embedded content is expected.

Your tabs are not embedded content. There just normal HTML forms and they should be.

  • Lack of code re-use across iframes as each has it's own code pool.

You also can't re-use elements and global data as each iframe is sandboxed. This means it's going to be a pain to extend for a fifth tab as you have to develop an entire new tab rather then plug into existing functionality.

I believe your main problem is not understanding that there are plenty of tools for writing high quality javascript applications to solve your problem for you.

Use backbone or spine or knockoutjs. You may also want to consider a templating engine of your choice (I would recommend EJS or Jade)

It is okay to use an iframe provided that you have the control over the browser which the application runs on.

Otherwise, you would run into problems like browser compatibility soon.

Hemant Tank

I had to get off this post to complete it - Alternative for iframes for jQuery ui tabs plugin - with support for postback

I didn't wanted a fully "JSified" ajax base model handling because it brings the business object level details in the presentation layer. So, to keep it abstract I ended up using a jQuery plugin jquery.forms.js which allows to ajaxify my forms.

Combined with the "partial view" concept of MVC I was able to achieve a complete AJAX postback solution (without making it complex or bringing my model level handling on client side as features in knockoutjs, backbone, etc... (they're great but I wanted to keep thing simple and in control (on server side))

Thank you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!