Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the hash (#) mean after a .js file?

what is the significance of the hash (#) here, how does it relate to the .js file:

<script src="foo.js#bar=1"></script>
like image 602
jsj Avatar asked Oct 18 '11 14:10

jsj


People also ask

What does hash mean in it?

Hashing is simply passing some data through a formula that produces a result, called a hash. That hash is usually a string of characters and the hashes generated by a formula are always the same length, regardless of how much data you feed into it. For example, the MD5 formula always produces 32 character-long hashes.

Why do they call it hash?

THE WORD "hash" is a variant of "hatch", which means "to inscribe with parallel lines", as in "hatchure" and "cross-hatch"; it derives from Old French hacher, meaning "to chop", and the dish called "hash" is so named because it contains chopped meat.

What is a hash in Crypto?

A cryptographic hash function is used for security purposes and constitutes the backbone of crypto security. A hash function turns a random input of data (keys) into a string of bytes with a fixed length and structure (hash value) The hash of a transaction makes it easy to identify transactions on the blockchain.


3 Answers

The hash after the script is used by the embedded script for configuration. For example, have a look at the provided example (facebook):

1. window.setTimeout(function () {
2.    var a = /(connect.facebook.net|facebook.com\/assets.php).*?#(.*)/;
3.    FB.Array.forEach(document.getElementsByTagName('script'), function (d) {
4.        if (d.src) {
5.            var b = a.exec(d.src); //RegExp.exec on the SRC attribute
6.            if (b) {
7.               var c = FB.QS.decode(b[2]); //Gets the information at the hash
8.               ...

In the script, each <script> tagline 3 is checked for occurrencesline 5 of the hash line 2 at the attribute. Then, if the hash existsline 6, the hashdata is extractedline 7, and the function continues.

like image 79
Rob W Avatar answered Oct 11 '22 09:10

Rob W


I doesn't do anything in terms of loading the script. What I am guessing is, the script itself looks for its own script tag, and picks out the piece after the hash (bar=1), and uses it to configure its behavior somehow. To do this, they probably have to loop through all script tags and match against the src attribute.

like image 37
airportyh Avatar answered Oct 11 '22 10:10

airportyh


It is probably used within the referenced .js file reading the raw URL and extracting the parameter (using something window.location, for example and parsing out what is after the #).

like image 24
Oded Avatar answered Oct 11 '22 09:10

Oded