Include local html file into iframe is slow


i need to include an html file added to the content filter as is (it’s an html email converted to an html file, and it has inline styles).

im using the line below to display it, but it takes almost 4 seconds to get fetched and rendered on the page.

<iframe src="<?= $page->file('email.html')->url() ?>"></iframe>

is there another approach or something i can change to make it render faster?

What do you mean by “an html email converted to an html file” ? Maybe if it’s slow, it’s due to the file weight, or something else.
Can’t you achieve that using AJAX call ?

Why can’t you include it in the template as is, why do you need an iframe? Does the file load loads of images? Or anything from external resources?

An alternative to the iframe would be to just read the file:

if($file = $page->file('email.html')):
    echo $file->read();

because when i tried to include it in the template as a file, it would break the main html page — it includes head and body tag.

so i though that i could either clean up the html in the email, or put it in a sandboxed environment.

yes, the file loads a picture, which is in the same folder.

i converted emails saved as rtf, into html with a CLI tool (don’t remember right now). and i got html pages maintaining the styles of the original email.

the email weights 4kb and the linked image 200kb, seems weird.

i guess it’s because of the iframe.

Hm, that’s really weird. How do you link to the file?

using $file->read() loads it instantly, though on the Timeline tab of the inspector, it still takes 4 seconds. but now the link to the image in the email is broken, i guess because i’m rendering it differently than through the iframe?

the image link is <img src="file.jpg">, and was working before.


it’s just an incorrect url :smiley:


the only downside of using file->read() is that i need to manually adjust each url… but doable.

Well, if the html file contains a complete html document, then $file->read() doesn’t make much sense.

yes it does contain a complete document!

my other approach would be to convert that html into markdown, and then apply custom styles only to the email…

What is your use case? You can of course use $file->read() if you include it into a naked template i.e. without any header/footer code. But currently I don’t see the whole purpose of this…

the website archives a series of art events, including email invitations.

i want to include each email maintaining the styles of how it was sent, and include it as is.

by inspecting the html of the email, the only useful bits are the styles included in the header. i can always move them elsewhere of course…

If you make the email template a separate page, you can simply include it into an empty template using $file->read()- If you want to include it into another template, you will have to use an iframe. Normally, it shouldn’t take ages to load, wonder what takes so long. What does the timeline say takes so long?

the timeline says rendering the whole html page takes 4 seconds, rendering the image takes a blip. mmh.

maybe i can add some animation while it takes time to load.

okay, on a server the iframe loads instantly, eheh.