what is the significance of the hash (#) here, how does it relate to the .js file:
<script src="foo.js#bar=1"></script>
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.
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.
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.
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.
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.
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 #
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With