Is it possible to specify a cache validator for a PHP file that serves JS content?

I’ve tried various methods and so far have the following in .htaccess:

ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresDefault "access plus 1 month"

# 1 month exp
ExpiresActive On
<filesMatch ".(gpdf|PDF|gif|ico|jpg|jpeg|png|GIF|ICO|JPG|JPEG|PNG|css|js|woff|CSS|JS|WOFF|ttf|TTF|txt|TXT|html|HTML)$">
  Header unset Set-Cookie
  Header set Cache-Control "max-age=2592000"
  Header unset ETag
  FileETag None
</filesMatch>

And the PHP file that serves the JS content has the following headers:

header('Content-type: application/javascript');
header("Cache-control: max-age=2592000, must-revalidate");

When I go to do a speed-test it still shows “specify a cache validator for js.php”

Is what I’m doing even possible or am I just missing something?


Source: stackoverflow-php

Woocommerce caches cart (Combined with W3 Total Cache)

I’ve experienced a weird issue on a site using WordPress + Woocommerce recenty. The site uses W3 Total Cache for page cache and browser cache and although i’ve set the woocommerce_cart_items cookie in the rejected list for page cache, the front page is beeing cached .
As a result i’ve issues with the cart ,empty on front page as is served as static, in other shop pages are regenerated and everything is fine.
To my understanding, pages are supposed to be cached if the cookie woocommerce_cart_items is missing ( so we have a guest customer browsing ), and after a product is added in the cart, woocommerce created a session and the cookie is stored so next time the frontpage is called it’s beeing regenerated and not served as static, is that right?
Is there a way to ensure this functionality?

Is this affected depending on the caching option selected (disk, apcu …)? if i decide to use redis for page cache , which is the best way to exclude such things from beeing cached?


Source: stackoverflow-php

Symfony2 cached controller won’t update

I’m quite new to PHP and have received some Symfony2 project to maintain. Now I’ve found out that when I update foo.html.twig, that page will not change until I perform the command console c:c -e prod. Until then the shown page will be foo.html_.twig (hence the underscore).

The problem is that I’ve changed a controller, let’s say BarController.php, but the new added value in that controller does not work in the .twig file, I think because the BarController_.php did not get updated with the clear cache command. What did I do wrong here?


Source: stackoverflow-php