2

I don't believe this is a framework issue. In my research it seems to be a browser cache issue but the things I've tried have not worked.

Unfortunately even though I don't want the user to click the back button but obviously there is no way (really) to block the user from clicking the back button.

This is the result of the form upload.

enter image description here

This works fine I get the expected result.

When the user clicks the back button they get the orignal form instead of the image that they just uploaded.

enter image description here after the user clicks refresh after clicking the back button from the submitted form they get the uploaded image that should show up.

enter image description here

I do have two templates layout.php and layout_wide.php

I have tried this in both templates.

    <meta http-equiv="cache-control" content="max-age=0" />
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="expires" content="0" />
    <meta http-equiv="pragma" content="no-cache" />

I have tried this custom helper...

<?php
function include_stylesheets_versioned()
{
    $response = sfContext::getInstance()->getResponse();
    sfConfig::set('symfony.asset.stylesheets_included', true);
    $html = '';
    foreach ($response->getStylesheets() as $file => $options) {
        if ((strpos($file, '?') === false) && (stripos($file, 'http') !== 0) ) {
            $file .= '?v='.sfConfig::get('app_resource_version');
        }
    $html .= stylesheet_tag($file, $options);
    }
    echo $html;
}
function include_javascripts_versioned()
{
    $response = sfContext::getInstance()->getResponse();
    sfConfig::set('symfony.asset.javascripts_included', true);
    $html = '';
    foreach ($response->getJavascripts() as $file => $options) {
        if ((strpos($file, '?') === false) && (stripos($file, 'http') !== 0) ) {
            $file .= '?v='.sfConfig::get('app_resource_version');
        }

    $html .= javascript_include_tag($file, $options);
    }

    echo $html;
}

I am ready to try putting it in a modal or an iframe to take the back button issue out for this form. But I have another form with a similar issue where putting into a modal isn't an option.

I did see the Post Redirect Get Design Pattern yesterday and think it may be a solution but I am wondering why the meta tags are not working at all.

I realize this may be a duplicate question but I couldn't find a solution that worked.

Has anyone else run into this and can someone please point me to a solution.

The app is sitting on a AWS instance and the Server is NGINX if that has any bearing on it.

Thank you in advance.

smugford
  • 769
  • 2
  • 10
  • 20

2 Answers2

0

please double check which your browser cache is clean and follow this article.

you need to set CONTENT="-1" for HTTP-EQUIV="Expires" and not to 0

you also need to use <meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache, no-store, must-revalidate"/> based on this answer

<HTML>
<HEAD>
<TITLE>---</TITLE>
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, no-store, must-revalidate">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
</HEAD>
<BODY>

Text in the Browser Window

</BODY>
<HEAD>
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, no-store, must-revalidate">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
</HEAD>
</HTML>

BUT HTTP-EQUIV is highly unreliable so you need to send HTTP header from NGINX so first create a configuration file and name it expires.conf then include it in your origin nginx confing:

server {
    listen ...;
    root ...;
    index ...;

    server_name ...;

    charset ...;
    include expires.conf; #here

    ...
}

in your expires.conf say that you don't want to cache static files (Or whatever you don't want):

location ~* \.(?:manifest|appcache|html?|xml|json)$ {
  expires -1;
}

Notes:

  • pay attention to cases of words. e.g. Pragma
  • usage of HEAD and META tag in bottom of your html structure is a workaround for IE cache policy.
01e
  • 691
  • 3
  • 14
  • I did see this article but the first comment says "This has got to be the most out of date article I've ever seen..." so i dismissed it. I've never seen the at the bottom of the page. Will try -1 – smugford May 26 '16 at 20:27
0

I need to redo my layout templates to follow the new standards. They were original created quite some time ago.

This works and gives me a new time result on the back button.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
 <?php
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
 ?>

<?php include_javascripts() ?>
<?php include_stylesheets() ?>
<?php include_http_metas() ?>
<?php include_metas() ?>
<?php include_title() ?>
<link rel="shortcut icon" href="/favicon.ico" />
</head>
<body>
 <?php echo $sf_content ?>
</body>
</html>
<?php echo time(); ?>

I think the big change is in the DOCTYPE

OLD DOC TYPE

<!DOCTYPE html>

NOTE****!!!!

None of the above worked in symfony 1.4.20

For those few of you that are still using 1.4 I had to put the following into the action to make it work.

    $this->getResponse()->setHttpHeader('Cache-Control', 'no-cache, no-store, must-revalidate, max-age=0, private'); 
    $this->getResponse()->setHttpHeader('Pragma', 'private'); 
    $this->getResponse()->setHttpHeader('Expires', 0); 
smugford
  • 769
  • 2
  • 10
  • 20