Why does JavaScript lack commands to import subfiles? [closed] - javascript

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 9 years ago.
Improve this question
Most programming/markup languages that I know have commands called include, import, load, require, input, etc. that call subfiles from the main file, but as far as I know, JavaScript does not have such feature, and a suggestion that I often see for such case is to insert a <script> tag into the dom (programmatically from the main file), which I think is very indirect. Why does JavaScript lack such feature? Was there any design decision?

who said no? Read about this tool: Helios Kernel
But will it be is conveniently for you?

If you use it with node.js for instance, it does have require().
Unlike most languages, JavaScript is generally client-side. If you want to do this from the client, how would you do that if the file you want to include is actually located on the server? JavaScript does have eval() and many other useful functions to do this, but you need to understand that you are dealing with requests through http and not files on a file system.

Related

Is there a default JavaScript file naming convention? [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 last year.
Improve this question
So I've just started building my personal website, and I need an HTML file, a CSS file, and JavaScript file. But, I'm not sure what to name my JavaScript file. Here are some of my thoughts:
"index.js"
"app.js"
"main.js"
Please correct me if there is a default JavaScript file naming convention. Otherwise, I might go with "index.js" because it sounds the most natural.
Help would be appreciated!
It is really up to you, although index.js, app.js, and main.js are usually what is used to name the main javascript file of an application. For others module or component files, use a name that describes what the code within the file does, like services.js for a file that handle everything related to services section of your application.
https://google.github.io/styleguide/jsguide.html
This URL shows JavaScript's naming conventions.
But naming is up to you.
Naming conventions come in many forms, but I recommend that you use the prescribed method.
This will make it easier for other developers to understand what you've made, and it's easier for you to understand what other developers have made.
Best regards.

Are JScrambler services safe for protecting javascript? [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 6 years ago.
Improve this question
So I recently stumbled upon jscrambler.com
This tool actually allows you to protect your javascript code, its fascinating. However, the service is cloud based and im wondering if this is really ok. Since im actually posting code on their servers. While others cant steal my code, it is still vurnerable to theft from within the the guys behind jscrambler.
Maybe im worrying too much. Is it safe to use jscrambler services?
You're right. Giving your code to a 3rd party to protect it is as counter-productive as it is counter-intuitive.
That said, browser users always have access to the underlying Javascript code. The most you can do is wrangle the source code by making syntactic changes that produce the same functionality but result in harder-to-read text.
This process is known as uglification or minification (since it reduces file size). UglifyJS is the most frequently used tool for this.

Concat or not to concat external scripts? [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
My site uses a variety of JS scripts. With the ones that I write, I concat to one master JS file.
I have a number of external scripts for things like Pinterist sharing, or Google's places API.
Should these be downloaded and concatenated into my master JS file or should I leave them as a separate call to each of their APIs, as so:
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>
I think concatination of external scripts is a BAD idea.
What about security fixes and updates? You would loose all of that. Many resources like Google etc get updated regularly, so you would have to check it, download it and concatinate. That is too much work for 'having one master JS file'.

Are modules a good idea in typescript? Or are they just added complexity? [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 9 years ago.
Improve this question
I come from the Java/C# world where namespaces are absolutely necessary. However, comments like these make me think that modules are of no utility in typescript (and javascript). For large typescript/javascript programs (probably several hundred .ts/.js files by the time we're done), are modules a good practice or do they just get in the way?
ps - I know that opinion questions are not allowed here. But, IMO, this is more a "please explain how javascript works" question.
Having a deep namespace hierarchy is mostly an overkill. Having a single top level namespace is definitely a good idea though.
e.g.
module appName{
class Foo{}
}
instead of
class Foo{}
But not so if you are using already using external modules (commonjs / requirejs) as they isolate code for each file.

JavaScript and Styles compression [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 3 years ago.
Improve this question
I understand the basic principles of script/style compression. What I would like to know is how do I integrate minified/combined scripts into my process and not interrupt my normal development flow?
I obviously want to use the regular files while developing then switch to the minified versions for deployment. I currently use YepNope to load my scripts. Is there some sort of conditional I could use to tell the browser to load the regular files?
Environment: VS 2010
My solution to this was to go with Microsoft's own Ajax Min its pretty nice. Compression is on par with some others I used.
As far as telling the browser to load minified versions or full, I added that into the post build script. Basically if you are in this particular environment then do not build the minified versions. Then in the js I have a little flag that points to one or the other depending on environment.
Hope this helps.

Categories