Script src with 'arguments' [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I often see that 'src' property in script tag has 'arguments/parameters' (I am sorry if I am not using the proper terminology, this is why I am asking). I would like to know:
What is the proper name?
Why is this done this way?
Where is it used?
Is there any advantage by using/doing it this way?
Here it is an example.
<script type='text/javascript' src='root/somedir.js?arg=somevalue'></script>

Basically, it depends of context. And yes, it's called query string.
In some cases it might be used as cache buster (e.g. ?timestamp={current_timestamp}) in order to avoid client-side caching of specified resource.
In other cases it might be used to generate script based on any condition (for example: api key, custom parameter, etc).
Assume you make call to js weather widget, and the documentation says that you should pass the city name as parameter to get the right data, e.g.
<script src="//some-weather-widget.js?city=Sofia"></script>
It's not perfect example, but I think you got the idea.

Related

Best way to use javascript in anchor tag [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
There are many ways to use JavaScript. When I use JavaScript with an anchor, I write code like this and I think this way is right.
Method One
But my co-worker uses JS like this.
Method Two
Is there a coding standard or are both methods correct?
DISCLAIMER: Inline JavaScript is, generally speaking, a bad idea, and 99% of the time you're much better off separating concerns, and using a library, such as jQuery, or whatever similar toolset that your framework of choice recommends.
Nonetheless, to answer your question, if you must use inline JavaScript, I recommend that you omit the "JavaScript:" keyword. It specifies a "pseudo-protocol," and is not necessary for modern browsers to interpret the code. It is a relic from the last decade, and there is a bug with some versions of IE:
"There is one (somewhat obscure) bug with the javascript protocol - in
Internet Explorer*, it will think you are leaving the page when you
click the link. If you are using window.onbeforeunload, then your
navigate-away message will appear at this time. For this reason alone,
we've stopped using the javascript protocol completely so we don't
have this bug show up because we forgot to check for it when we add a
navigate-away message to some page."
When do I need to specify the JavaScript protocol?
https://bytes.com/topic/javascript/answers/504856-javascript-pseudo-protocol-event-handlers
Both the ways are ok but in first way you should use a external JS file. Otherwise it is ok.
For small tasks and events second ways is good.

How to show client the prototype without using a server for a web site [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I have created a webpage that takes a skill survey of students of a particular college but they are not ready to give me server yet they would want to see the prototype first how to show them the prototype without using the server but just using the web page that I have created?
A prototype shows how it works without actually working. So instead of getting real data, it can show fake data.
Your survey can show just two or three questions, and these questions can be hard-coded or loaded from a mock object, instead of loaded from the server. Also, instead of actually saving anything, it can just jump to the next question and show a text saying 'Thanks' when you are done.
That way, you can see if your survey has the right look and feel, and they can see that too. Also, it may make it a bit more clear to the server-builders what kind of implementation they need to make. A visible, 'clickable' prototype makes it easier to discuss details in the implementation.

How do I validate HTML with Javascript? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I would like to verify that a string is valid HTML, like the W3C Service does. I specifically don't want any browser corrections (like closing open tags), which precludes options that create DOM elements and read the HTML from them. It will run very frequently, so I really need to run it locally. Libraries are OK, jQuery is OK.
Edit #1: I'm asking about HTML validation, not form or input validation.
Edit #2: What I need is basically a Javascript implementation of the Nu HTML Checker.
Provided you're running node.js or python on the server side you can use a library like html5-lint by Mozilla to do all the heavy lifting for you. And for the java world there is a similar library jtidy and there are countless of similar libraries out there.

What impact have JS erros in performance? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Does anyone if/how to many JS errors affect the server? Does it affect page render?
I have different errors in different sites (and I will fix them) but does it affect anything?
Here is an example:
The javascript errors most likely won't affect the server, since Javascript is executed on client side.
When it comes to page render, javascript errors might break your page. Let's get for example angular single application, if there is javascript error, you're most likely to see nothing at all.
Errors such as undefined is not a function might be sign for passing value instead of callback. For example:
$.ajax("url.php", 32); // the second parameter must be callback/function
You must review your code and fix them, because these errors are clear sign that something in your application is not working.

Javascript - Dynamically Create it? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have a set of users with different permissions. Depending on what permissions they have, they should only have access to a certain javascript files. In terms of speed, is it better if on every instance of their visit, I check the permission of that user, create one javascript file that contains ALL the javascript commands accessible to that user, and load that file into the view?
Or is it better to have multiple javascript files, call them page#_permission# (for instance, page1_permission10.js), and just load the corresponding files every time the page loads?
Thanks
It is probably faster to load in only the JavaScript that is needed BUT...
It probably will not be significant enough to warrant the effort. Futhermore, you may find youself in debugging hell just to save a few ms.
Firefox and many other browsers have built in tools which describe how much time it takes to load a page. Below a recent example for stackoverflow.com. You can perform a similar operation you site and locate the bottlenecks.

Categories