JavaScript Minification & Concatenation Best Practices? [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
If you are building a 10 page site and using uglifyJS to minify and concatenate all the javascript code to a single file, what is the best practice for optimizing code globally across the site?
Let's say for arguments sake all pages have shared code and have some unique code. Do you include all the code into the single minified javascript file and include code that won't be used on every page? Or should you create an additional minified javascript file for every page with the unique code?
I know the best choice is probably unique to every site but if there is a general rule of thumb that applies, I am curious to know what the best approach would be.

Related

Is naming minimized files with "min" necessary? [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 2 years ago.
Improve this question
As you know, the minimized version of files that include CSS, JS and etc. are also named as "xxx.min.js". For example "bootstrap.min.js".
Is it in any way significant or necessary to include ".min." in a minimized file name in terms of SEO or semantics? Or is it just a convention to be followed?
It is just a convention.
It stops you, the developer, from getting your production and development files muddled.
If you provide your code as a download for other people to use, it makes it clear which version is which.

javascript/Jquery code organisation [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'm creating a php app where almost all requests are in ajax and some Jquery effects, so some of my pages are up to 2000 lines of code, all my jquery in one big $document.ready{}, is it normal? should I be ashamed of showing this code to other developers? or is there a better way of organasing Jquery code ?
Like how many others have said, if it's maintainable and easy to read then it shouldn't be much of an issue. However, in my experiences, code that is organized into separate logical modules were MUCH easier to read and maintain than one long document.
With that being said, the typical workflow these days with tools such as browserify would be to refactor and separate the code such that each file executes a specific task for development purposes and when it is time to deploy to production, one would use a build tool to group/minify and optimize for the browser.

When should I save Javascript code into different files or the same file? [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 8 years ago.
Improve this question
I am a beginner of Javascript. I have done some Python and Java before.
I am not clear when and why we should store codes into different .js files or the same file.
Is there any conventions and rules for this?
Well, the main reason of javascript code into different folders is for organization.
Similar to Java or Python, or any language, you should organize your code in different files to get a code that any other in your team can read easily.
But in production scope, or better said, in your website, it's a best practice to reduce the number os javascript files for performance reasons. If you have 2 javascript files, the server will send 2 request. In the case that you have 10 or 15 files, the web will have performance problems.
So, in development it's important to have multiple files to organice your code, but in production you can minify then into one. Uglify is a good tool to monify your code into one file.
Hope it helps.

How big should a file be before I don't inline it in html? [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 8 years ago.
Improve this question
Google recommends optimising web pages by inlining small CSS & javascript.
Ref: https://developers.google.com/speed/pagespeed/service/InlineSmallResources
But at what point should we stop inlining, is there a recommended maximum number of characters that a file should be before it is better to reference instead of inline the file?
Obviously this isn't a complete list, but I think this is a decent set of guidelines.
Situations when inlining might be beneficial:
Styles or scripts are only used on that page
Single page application
Styles are determined to be "critical", and will make the page appear as if it is loading faster. See this article: http://css-tricks.com/authoring-critical-fold-css/
Situations when inlining might be harmful:
Styles or scripts are used on multiple pages - if inlined on each page, they will not be cached and need to be downloaded again on each page

Best practice for including css and javascript files [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've always wondered about including javascript libraries and a mess of stylesheets in pages that don't ever use them. It got me wondering if maybe performance would improve, however slight, if I were to include these files on an as needed basis. Is there a best practice to go by on this? Some of these javascript libraries are very large and if they're not needed, it would seem to me that they shouldn't be included.
I'd like to hear the thoughts from others on this.
I think you are talking about Asynchronous Module Definitions (AMD).
One of the more popular implementations of this is Require.js. Check it out.

Categories

Resources