This question already has answers here:
Why pass parameters to CSS and JavaScript link files like src="../cnt.js?ver=4.0"?
(9 answers)
Closed 3 months ago.
What is "?_=3.5-SNAPSHOT-Dev" mean after ".js"? I do some research on google but no idea what it mean and what it use for
<script type="text/javascript" src="js/jquery-3.5.1.js?_=3.5-SNAPSHOT-Dev"></script>
It depends on the server that's serving your Javascript. Generally, variables like those on JS files are used for cache busting. I think in your example, 3.5-SNAPSHOT-Dev could be a release tag. If this JS file is now on your own machine, you can safely discard the ? and anything after that. If you're getting this from another server somewhere, seek out documentation about that server to see what they use the _ variable for.
Related
This question already has answers here:
How to use external ".js" files
(6 answers)
Closed 6 years ago.
Really basic javascript question:
Can I save code within <script>...</script> in a different file and include it?
Will it work exactly the same?
Can I include it in the exact same place as the <script>...</script>?
Yes. Put a src attribute (where the value is the URL of the script) on the <script> element (then leave the element content empty).
Save your Code in a file, name it xyz.js and include it:
<script src="path/xyz.js"></script>
This question already has answers here:
Can I change all my http:// links to just //?
(7 answers)
Closed 9 years ago.
Today I came across this:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
Which I think should be this:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
Can someone explain why all the CDN folks omit the http: in their include snippets? CloudFlare does it too:
//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.2/jquery.min.js
But why? Does even the dumbest browser get this or is it safer to just add http:?
Look http://www.ietf.org/rfc/rfc3986.txt for "relative reference". The path referenced is relative to used scheme. So, if your website is http://www.example.com the http-part is the scheme. Now in "//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js" the // part signals, that you want to go relative to the scheme of your site, meaning in this case relative to http.
This question already has answers here:
How do I get query string value from script path?
(5 answers)
Closed 8 years ago.
I wanna know is this possible I pass get parameters for a javascript file and use them in codes?
I have this in html:
<script type="text/javascript" src="/javafile.js?q=somtext"></script>
know how I use this "q" parameter in my script codes? is this possible?
You can either:
Generate the JS dynamically with a server side language and read the query string there
Assume that the JS is the last <script> element so far in the DOM and parse document.scripts[document.scripts.length - 1].src
Note that if the script element has been added dynamically (i.e. with JS), it might not be the last script in the DOM.
I think Quentin's suggestion is the answer to your question.
I usually use an alternative way for this, which may also help you:
Make sure that your javascript is written in a library form, and make sure that you have an instantiate method/function inside your javascript that allows you to pass parameters (or better, as an object)
// on dom load:
library.init({ var1: value1, var2: value2});
This allows you also to load your javascript in a different way, and allows for cleaner code.
Or you can use option 3: use a library that has this functionality, e.g. MooTools: http://mootools.net/docs/more/Types/String.QueryString
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How can I obfuscate JavaScript?
Hi I need to Encode my js file to upload my host when save my page i dont want user see my js and my javascript code any body idea
you can't encrypt or encode your JS as the browser needs to run it.
The only thing you can do is to minify it, so it gets hard do read. But someone with the right tools and time will be able to reconstruct the code.
Hi there is no way to encript a js page, but there are a few tricks you can do to obscure te code.
First, you obscure the code, by changing the variable to value that do not make much sense. If you do that, keep a original copy.
ie.:
var firstname = 'Paul'; // change it to var fn = 'Paul'; or var 00110011 = 'Paul';
function returnFirstname(){} // change it for rtnFN011010(){}
In order to do that, you would need to program a script that does it for you.
Second, minify your code : http://fmarcia.info/jsmin/test.html
Good luck
The is no definitive way to do this, the best you can do is minify your js file. Search Google for "JavaScript Minify", there are plenty of tools out there...
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
How can I obfuscate JavaScript?
Is there any way to protect my js file or javascript function from user to view?
You could minify/obfuscate it but the function would still be visible to the user.
Nope but you can always obfuscate. just look up online for javascript obfuscator. It makes code harder to read but it'll still be decodable.
If you need to hide code may I suggets something serverside such as php, aspx etc..
Like Darin sayd, you can obfuscate the code.
But if you want execute a js file on a browser, the user can get the source code. There is no way to avoid this.