Why use CSS hashed styles and Javascript file names?

If you look at the code for some of the most popular websites, I have seen many times that the CSS and JavaScript file name looks like this:

<link type="text/css" rel="stylesheet" href="//sample.com/css/css__k3sYInttBtNNuJgtPSyqaYy9vVxS4qTZLrfs1ujQB9g__SH_QaIH3bnSp3nOw8n8afhszfHJlxVt51qRlrrrOnk0__fBOuweRojwN82z7EY4v-sVsMwU_P_vZSaU3fmyho6Do.css" media="all" /> <script type="text/javascript" src="//sample.com/js/js__-V23Vc4PVahQcqfyxss_rmNogErBARnPCvI7oPXC0qQ__O-yO5Gg8pRRaefl4d0X9qXUJTOSHq0yazxF-4tJCU_k__fBOuweRojwN82z7EY4v-sVsMwU_P_vZSaU3fmyho6Do.js"></script> 

It looks like the filenames have been hashed, and I don't know what the reason is. Therefore, I have the following problems.

  • What is the purpose of using this method?

  • I saw very complex folder names . Why is this?

  • Are there any security issues?

  • Can we dynamically change file / folder names using PHP for maximum security?

I am a little new to this area.

+5
source share
1 answer

You can assume that these file / folder names do not work on developers at the development stage, but rather an artifact of the file assembly process . JavaScript and CSS are often embedded in a single file from several source files, which includes more or less compilation / transpilation and linking steps.

The reason you want the file name to / include the hash of the file is because this causes the cache to be invalidated whenever the file changes . Static files can be cached by the browser, server, and a number of other agents between them. This is normal if the file does not change. However, when a new release is published, the user must be provided with this new version. If the resource file name changes, the browser will always request a new version of the file from the server, and not use the cached version.

You should not rely on complex file names such as this as a security / authorization function . File names are specified in the application index file and are thus known to the end user. In addition, obscurity is generally a bad idea.

+5
source

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


All Articles