basagabi
basagabi

Reputation: 5064

how to encrypt css/js filename

Is there a way to encrypt the filename of the css/js file? I notice that when I view source the website, the filename of the css and js files are encrypted like this.

<link href="/assets/css/builds/73e15c8a3cf6409214bbf8a742e9b5d41403226617.css" rel="stylesheet">

<script src="/assets/js/builds/217651bd25211390d62315e92b525f667014020626.js"></script>

Is there a script to do so?

Thanks in advance!

Upvotes: 1

Views: 1285

Answers (2)

Ja͢ck
Ja͢ck

Reputation: 173642

This is typically part of a deployment step that aims to:

  1. reduce the number of requests by combining all scripts/styles on a single page together.
  2. minify the combined scripts/styles (optional, but recommended)
  3. avoid unintentional cache hits if you make changes to the scripts/styles.

It does not add security in any way

Once the combined scripts/styles have been built, the contents is typically hashed using either md5() or sha1() and that hash becomes part of the file name; it provides a unique filename as well as prevent cache misses if the files didn't change.

I'm not aware of generic tools that perform this for you; I've written one for my own purposes, though, it's not rocket science after all.

Upvotes: 1

Bob Brown
Bob Brown

Reputation: 1502

Well, you could run an ordinary filename through a cryptographic hash function like MD5 (which should still be OK for something like this, but which has known weaknesses for use in digital signatures.)

If you run "standard" as in "standard.css" through MD5 using the tool at http://www.fileformat.info/tool/hash.htm you get c00f0c4675b91fb8b918e4079a0b1bac. I'm not sure what this buys one, other than to obscure a name.

Edited to echo Jack's comment that you haven't really protected anything, just obscured a name, which is likely to make things harder on you, rather than on others!

Upvotes: 1

Related Questions