PHP content caching for javascript and css

I have a unique problem that is difficult to solve with Google. I am combining all my javascript and css into separate php files that use require_once () to pull out the contents of the files. The javascript file looks something like this:

<?php
header('Content-Type: text/javascript');
require_once('jquery.form.js');
require_once('jquery.jqtransform.js');
require_once('jquery.validate.js');
?>

My particular problem is that web browsers will “see” that this is a dynamic page due to the php file extension, and then request content again every time the page loads on the site. What I'm trying to do is get the time of the last request from the browser , and then check the file modification time to see if I really need to send the contents of the file again. It is difficult to find the time of the last request by the user. In addition, I have not yet begun to solve the problem of finding the last modified date of the files that are included, so if there is information about searching for file file information on the server , this should also be taken into account.

Just to be clear, the reason I do this is because (I think) it uses gzip compression better than separate gzipped files.

Thanks in advance

+3
source share
5 answers

Your premise is incorrect. Browsers do not “see” the PHP file extension and do not decide to cache anything. See http://www.enhanceie.com/redir/?id=httpperf for information on how browsers work.

You must set the ETAG for the response, and then you can simply check the If-None-Match request header and return 304 if the content has not changed.

+2
source

. . Javascript PHP CSS PHP, :

  • ;
  • Gzipping;
  • ;
  • .
+3

, . . , , .

, ?>. .

0

Alister Bulman , , . , :

Minify - code.google.com/p/minify - , - , , , gzipping , . - 10 '10 10:44

0

gzipping apache mod_deflate.

apache mod_rewrite html js php , .

- :

RewriteEngine On
RewriteRule (.*).js $1.php

.htaccess .

-1

Source: https://habr.com/ru/post/1727897/