K
K
Kirito Asumo2021-05-16 23:02:04
PHP
Kirito Asumo, 2021-05-16 23:02:04

Am I doing the right thing with loading JS|CSS via php?

Initially, my site structure consists of two root directories, one of which stores files that are not accessible to the user directly from the web browser, i.e. core files and files available through the web, i.e. public files.

At the moment, I store my CSS/JS in the public directory and load them using standard methods. In order to reduce the division of directories and information available to the user in public, I want to transfer the whole thing to the core directory and from there to cling to them using the php entry point.

But reading articles on the Internet on this method, I additionally found out both the pros and cons.
Pluses are:
1. Inaccessibility of files directly.
2. Loading only those files that are needed at the moment.
3. Reducing HTTP requests.
The cons are:
1. Lack of caching.

This is the only minus that strained me with the fact that if a user visits 10 different pages, then the same thing will be loaded 10 times for him.

I poked around and found that the entry point can also be cached. And found the relevant HTTP headers, for example:

Cache-Control: no-transform,public,max-age=300,s-maxage=900
.

Now the question is, is it worth it? What other pitfalls can be and what is better, direct loading or through the entry point.

UPD: Or maybe take and compile JS / CSS files into one CSS and JS file, respectively, before publishing the site and feed these minified files in one heap in the standard way?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question