View previous topic :: View next topic |
Author |
Message |
RomanTarasov Smarty Rookie
Joined: 21 Nov 2014 Posts: 6
|
Posted: Sun Dec 07, 2014 1:15 am Post subject: Page loads twice when echo long output before template. |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Dec 07, 2014 5:00 am Post subject: |
|
|
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 |
|
RomanTarasov Smarty Rookie
Joined: 21 Nov 2014 Posts: 6
|
Posted: Sun Dec 07, 2014 6:26 am Post subject: |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Dec 07, 2014 3:56 pm Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sun Dec 07, 2014 5:02 pm Post subject: |
|
|
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 |
|
RomanTarasov Smarty Rookie
Joined: 21 Nov 2014 Posts: 6
|
Posted: Sun Dec 07, 2014 6:06 pm Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sun Dec 07, 2014 8:17 pm Post subject: |
|
|
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 |
|
|