|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
edelacruz Smarty Rookie
Joined: 10 May 2010 Posts: 25
|
Posted: Thu Jul 24, 2014 11:01 pm Post subject: (solved issue... not related to smarty) 304+content+chrome |
|
|
EDIT: It turns out to have nothing to do with Smarty. Moderators, feel free to move or whatever. /EDIT
I don't have a very detailed report or steps to reproduce. I am just throwing this out there in case it is something you have seen before and know the cause and solution.
Occasionally, my templates are rendering with unexpected data at the beginning.
The data includes what appear to be http headers.
I am using template inheritance. The output I get looks kind of like this:
Code: |
</div><div>some random content from one of my sub-templates</div>
HTTP/1.1 200 OK
Date: Thu, 24 Jul 2014 22:49:28 GMT
Server: Apache/2.4.7 (Win32) OpenSSL/1.0.1e PHP/5.5.9
X-Powered-By: PHP/5.5.9
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Set-Cookie: PHPSESSID=kcnu53pfodc4i1d69fem8gcsj6; path=/
Last-Modified: Wed, 31 Dec 1969 17:00:00 GMT
ETag: 9052faf7ebf01cb30513804cf5f5e56e
Content-Length: 42802
Keep-Alive: timeout=5, max=98
Connection: Keep-Alive
Content-Type: text/html
<html><head><title>page title</title></head><body>The correct and complete html is rendered here, after the headers</body></html>
|
Everything after the http headers seems to be the expected data.
Does anyone know off-the-top of their head what would cause http headers to be rendered? (using fetch()).
tia
Last edited by edelacruz on Fri Jul 25, 2014 8:39 am; edited 2 times in total |
|
Back to top |
|
edelacruz Smarty Rookie
Joined: 10 May 2010 Posts: 25
|
Posted: Thu Jul 24, 2014 11:07 pm Post subject: |
|
|
note that it never happens twice in a row (if I do browser refresh the problem goes away for some time, and the shows up again later, intermittently) |
|
Back to top |
|
edelacruz Smarty Rookie
Joined: 10 May 2010 Posts: 25
|
Posted: Thu Jul 24, 2014 11:17 pm Post subject: |
|
|
It seems like it is getting confused and partially rendering one template and combining it with the actual render.
For example, I run js and css through smarty. In my js rendering, I am seeing some of the content from the css file at the beginning.
Something like this:
Code: | .SomeClass
{
color: #333333;
}
.SomeOtherClass
{
font-size: 120%;
}
HTTP/1.1 200 OK
Date: Thu, 24 Jul 2014 23:09:10 GMT
Server: Apache/2.4.7 (Win32) OpenSSL/1.0.1e PHP/5.5.9
X-Powered-By: PHP/5.5.9
Cache-Control: public, max-age=259200
Set-Cookie: PHPSESSID=kcnu53pfodc4i1d69fem8gcsj6; path=/
Content-Disposition: inline; filename="Markets/Admin/Products/ProductEdit.js";
Last-Modified: Thu, 24 Jul 2014 13:45:13 GMT
ETag: 448f6da2bf5f9bd67d480f4beb022a85
Content-Length: 13255
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: text/javascript
function jsFuncTest()
{
alert("hello");
}
function jsFuncTest2()
{
alert("world");
}
|
It looks like it is combining my css template and my js template, and putting http headers in-between them. These files are called separately and should never be combined. They do not inherit nor include each other.
Also, the .css content is not the entire .css file, just a fragment of it. The js is complete.
They have nothing to do with each other except that:
1) They are both requested by the same html page
2) they have the same root file name (different extensions)
So in other words, I have three files:
Homepage.tpl
Homepage.css
Homepage.js
Homepage.tpl includes the .css and .js files using standard html <link> and <script> tags.
If I use firebug to inspect the included files, I see the .js file is littered with this css and http headers.
If I hit f5/refresh, the problem goes away for some time. And then, it will happen again later. Refresh browser always seems to fix the issue for a time. |
|
Back to top |
|
edelacruz Smarty Rookie
Joined: 10 May 2010 Posts: 25
|
Posted: Fri Jul 25, 2014 1:15 am Post subject: |
|
|
It looks like it has something to do with caching.
If I delete all compile and cache files, the first render works fine. However, subsequent renders give me the described behavior in seemingly random files.
I tried turning off caching in smarty with
Code: | $smarty->setCaching(Smarty::CACHING_OFF); |
However, I still have the problem. I see there are still a couple of files being generated in the template cache folder. Not sure if that is correct behavior.
I also removed all {nocache} tags. Didn't seem to make a difference.
I tried downgrading to 3.1.17. Same result.
I feel like it is something I am doing to cause this, as I have not seen this problem before. |
|
Back to top |
|
edelacruz Smarty Rookie
Joined: 10 May 2010 Posts: 25
|
Posted: Fri Jul 25, 2014 1:30 am Post subject: |
|
|
Ok I'm completely confused.
The problem only seems to happen in Chrome. In firefox, I cannot make the problem happen! Very odd. This should have nothing to do with the client.
Also, It seems like if I close the chrome debugger, I have no problems. I cannot guarantee the problem doesn't still occur becuase I dont see my debugging console. but all functionality seems to be fine, which indicates the files are loaidng correctly.
I;m going to turn caching back on and if everythign works in firefox + chrome with no debugger, then I'll submit a bug to google I guess.
Any insight appreciated. I'm at a complete loss.
EDIT: still having issues on chrome even without chrome dev console turned on. It is intermittently outputting the html as text to the screen, along with the HTTP response headers, preceded by some random template fragment. This is driving me mad! I'm going to use firefox for a while and see if it pops up.
EDIT: I am unable to reproduce the issue in firefox. In chrome, it happens often.
Have I lost my mind? |
|
Back to top |
|
edelacruz Smarty Rookie
Joined: 10 May 2010 Posts: 25
|
Posted: Fri Jul 25, 2014 8:37 am Post subject: SOLVED... had nothing to do with Smarty |
|
|
I found the problem.
The issue only occurred when I was returning http 304's.
The problem was that I was still sending the full content, despite telling the browser that the content had not changed (304). Chrome apparently used to, but no longer does, ignore the content if a 304 was returned (as the other browsers are doing). It seems to count the bytes of data returned against some sort of content length or buffer length counter thus truncating messages and causing weird side-effects.
Anyways, this is good news. Because I was hurting my app's performance by returning a bunch of content unnecessarily.
Sorry for trying to blame smarty! |
|
Back to top |
|
|
|
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
|
|