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.
Related
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 4 years ago.
Improve this question
At the moment Im using a bunch of script elements which are referring cdn/local files which is not so great.
I think I would like to declare all required packages using npm/yarn and serve cdn files with self hosted fallback (is this even a good idea?).
Should i go for a webpack/browserify solution or is this overkill for this purpose (because AngularJs is already handling dependency injection by itself)? Im getting somewhat lost in the amount of frameworks/information about this topic.
This is an opinion question, so we can only try to figure out what we would do given our knowledge of your needs. With that grain of salt:
What you are describing sounds like way overkill. Unless your performance needs are huge, manage your dependencies with npm and package them with your releases. If you really need to, use a build tool to minify and package your resources together (like webpack).
There are tons of great JS build tools, and if all of the boilerplate is overwhelming, take a look at something like Yeoman which can help out with that.
In my opinion, a self hosted CDN is probably the worst option possible, because it adds huge support requirements with almost no benefits, because as soon as you stop caring about this project someone else will have to refactor all of your code to new CDNs or local resources.
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
I have an angularjs project with gulp configuration.
In my gulpfile.js I merge all my code to a bundle.js file. I also add 3rd party library code there, minify it and it works fine. I don't understand what it will improve. I read a lot of articles, but couldn't find anything to make me understand. All it writes is how it is better than requirejs. I don't even use requirejs.
Browserify is a particular way to merge all your code. If you're already doing so and it works well for you, then you don't need it.
Once your project grows bigger, you're probably going to need a better way to structure your code into modules. That's where browserify helps you a lot. It also makes it easy to use many of the modules you find on npm.
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 some questions about Javascript.
Most of my website's pages use js. For better performance, what should i do ? :
Write all of my js code in one file and link it with my pages ? Or one js file per page ?
Is it a bad manner that i never mix js into my html ? I like to have separate things (html, css, js)
Thank you.
For maintainability
Keep separate pages while developing the app, so that any one can make out which feature has been coded where.
For performance
Before deploying it for production, minify your js and css files so that there are less network calls to download those files.
Is it a bad manner that i never mix js into my html ?
No, having non-intrusive js is both good for readability and it is good for performance too since it gives you a chance to minify the js files. You can't minify inline js.
My experience is writing a relatively big website in ASP.MVC .
I did not write all the javascript code in one file because that would have been difficult to manage. I made a folder that included multiple javascript files, each having its own purpose.
If the javascript is more than say 10 lines of code, and you can put it outside the html file, i would advise so, because it is faster to look at .
It is easier to just have one .js file for all pages, but it is better for readability if you have multiple files.
Mixing javascript into HTML can be useful but it depends on your needs.
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
How many classes/functions are best put into a module (which is later required, f.ex. by RequireJS, the Mozilla addon loader, ...)?
As the module seems to be imported wholesale (contrary to f.ex. Python, where you can do from module import class), would it be best to keep them as small as possible? Any other guidelines?
What is the best practice?
(There are similar questions about Java (which recommends "the more granular class layout you have, the better"), Python (which allows for more objects and states "Python is not C#/Java. Trying to bend it to make it look like $other_language will cause frustration and poor user experience") , etc, but nothing JavaScript-specific appeared.)
Maybe these questions were old enough to pass the site standards then. Nowadays, it might be really too broad for some.
I personally do the following when using RequireJS:
One class per module
Module file named after the class name
This allows for easy maintenance, plus dynamic loading of the needed classes.
Only drawback could be the amount of files, but you can bundle the ones most used later using RequireJS optimization features.
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.