Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Page loads twice when echo long output before template.

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
RomanTarasov
Smarty Rookie


Joined: 21 Nov 2014
Posts: 6

PostPosted: Sun Dec 07, 2014 1:15 am    Post subject: Page loads twice when echo long output before template. Reply with quote

When i echo 4096 characters before displaying template, it reloads page upon finishing loading it the first time.

Its same with flush() or without, its just easier to see this way.

Its not browser fault as when i comment out $smarty->display() function it works properly.


Code:

<?php

...
//include smarty etc.
...

echo "One";
echo str_pad(null, 4096, ' ');
flush();

sleep(3);

echo "Two";
echo str_pad(null, 4096, ' ');
flush();

$Smarty->display("page.tpl");

?>



Using Firefox v33 and Smarty v3.1.21 .
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Dec 07, 2014 5:00 am    Post subject: Reply with quote

I can't reproduce your problem and there is no way that Smarty itself does reload the page.

Or does your page.tpl contain some content which may force it?
Back to top
View user's profile Send private message
RomanTarasov
Smarty Rookie


Joined: 21 Nov 2014
Posts: 6

PostPosted: Sun Dec 07, 2014 6:26 am    Post subject: Reply with quote

Had to backtrack a lot of code however found it where i least expected.

Its <meta charset="utf-8"> that causes it., try put this in template file and see if it redirects.

Code:


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">

    <title>Some Page</title>

</head>
<body>

Hello World!

</body>
</html>




Guess its browser bug after all?
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Dec 07, 2014 3:56 pm    Post subject: Reply with quote

With your template code I can reproduce it with Firefox but not with Crome.

Anyway it must be a browser problem because it happens also if you don't use Smarty and just echo the template code.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sun Dec 07, 2014 5:02 pm    Post subject: Reply with quote

If your HTTP header charset doesn't match the meta charset, of course the page will be redrawn to render it with correct encoding.
Would that cause an actual request of new copy of the page, depend on a browser, I suppose. But it shouldn't.
Back to top
View user's profile Send private message
RomanTarasov
Smarty Rookie


Joined: 21 Nov 2014
Posts: 6

PostPosted: Sun Dec 07, 2014 6:06 pm    Post subject: Reply with quote

U.Tews wrote:
Anyway it must be a browser problem because it happens also if you don't use Smarty and just echo the template code.


In my case when i comment out $Smarty->display("page.tpl"); (no smarty template loaded) it does not happen.




AnrDaemon wrote:
If your HTTP header charset doesn't match the meta charset, of course the page will be redrawn to render it with correct encoding.

Great, setting character encoding in headers before printing output fixed the reload issue.
Code:
header('Content-Type: text/html; charset=UTF-8');


Wonder though character encoding needed to be set in header as i only used english characters in echo...
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sun Dec 07, 2014 8:17 pm    Post subject: Reply with quote

RomanTarasov wrote:
Wonder though character encoding needed to be set in header as i only used english characters in echo...

The browser don't know, neither care, what characters are used on page.
It look in headers and prepare the rendering in specified charset, then it encounter meta tag and redraw the page in "correct" encoding.
Though, setting such things in PHP code isn't the best idea. Add appropriate settings to web server configuration, or your PHP configuration, if you run PHP in CGI mode.

The bottom line is, META tag is to specify encoding for offline pages. You MAY (and probably SHOULD) specify it, 'cause user may wish to save the page for personal archival purposes, but for viewing online, you MUST specify correct metadata on protocol level. (That means headers for HTTP.)
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP