English 中文(简体)
Including HTML fragments in a page - methods?
原标题:

This is an extension of an earlier questions I asked, here:

Django - Parse XML, output as HTML fragments for iFrame?

Basically, we re looking at integrating various HTML fragments into a page. We have an small web app generating little fragments for different results/gadgets, at various URLs. This is not necessairly on the same domain as the main page.

I was wondering what s the best way of including these into the main page? We also need the ability to skin the HTML fragments using CSS from the main page.

My initial thought was iFrames, however, I m thinking the performance of this might not be great, and there s restrictions on CSS/JS manipulation of the included fragments.

Are SSI a better idea? Or should we use php includes? or JS? Any other suggestions? The two main considerations are performance of the main page, and the ability to style/manipulate the included fragments.

Cheers, Victor

最佳回答

This sounds similar to what Facebook Platform applications do. One kind simply uses IFRAMEs, the other takes output from a backend and transforms it -- <fb:whatever> elements are expanded, JavaScript executed, and things like buttons are skinned. You could look at them for an example.

Using IFRAMEs would probably make things complicated. By default you cannot modify styles inside them from the outer frames, but you could probably use something like Google Closure s net.IframeIo to work around that.

I would try loading widgets using cross-domain scripting. Then you can add the widget s content to the page, however you wish, such as inserting it into the DOM.

问题回答

iFrames should not be a problem performance-wise - It won t make a difference whether it s the browser doing the querying our your server. You may get design problems though. SSI and PHP are more or less the same, but they both have the same problem: If the source page is down, rendering of the whole page is delayed.

The best thing performance-wise would be a cached PHP solution that reads the snippet, and is thus less vulnerable towards outages.

Funnily enough, I have written a PHP-based tool for exactly this purpose, and the company I wrote it for has agreed on publishing it as Open Source. It will be at least another four weeks, though, until I will get around to packaging it and setting up the documentation. Should that be of any interest to you despite the timeframne let me know and I will keep you updated.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签