What js/css files should I bundle? [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
I am looking into the bundling features of ASP.NET 4.0 and am just curious what rules/practices people follow when deciding which files to bundle?
Should I group things by what they are, like put all jQuery files together or is it a good idea just to bundle up all files that are used in the same place?

I recommend reading this tutorial on bundling and minification
bundling and minification
Personally, I like to have one css bundle and one js bundle per page. Each bundle will only contain the files needed for that page. Keeps the http requests and size down.

I think how to bundle your files can be largely subjective. The only thing I think most everyone would agree upon, is you should organize your files once you have more than just a few.
If you are working on a simple site and you only have a few JS files and one CSS file, I don't see a problem with putting them all in the same place.
Once you get multiple files I like to at least group them by type:
/lib/css
/lib/js

Related

How to structure the JS? Put the code in a unique file or require the necessary JS code in the file where its used? [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 4 years ago.
Improve this question
Do you know if is better to have a unique file with all JS or is better in each file require the specific JS that is necessary for that specific page?
The project sould stay better structured requiring the JS specific for each file.
But in terms of performance do you know if is basically the same or not?
For a small JS snippets is always better to implement it only on pages you need.
But, for big classes, framework or huge functions is better use single file with an CDN. That way is better performance and finaly better to maitenance and for developing is better to stay organized.
As second, in single file you can easily do minified version fully automated.
I prefer creating a unique JavaScript file and then linking it to the html file. It is the most efficient and organized way of structuring your code. But if the amount of code is very small and only required for that single page, inline JavaScript is preferred.
Performance: External JavaScript is always faster because the browser can cache an external file but Inline JavaScript will always be loaded afresh and hence is slower.

How to write own scaffolder (like RoR has?) [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 would like to create own scaffolder for websites, something like Ruby On Rails has:
rails g modelname fieldlist
But for my own purposes - it should generate HTML, CSS and JavaScript files in proper folders (folder paths will be taken from configuration file) with specific content.
My question is: which language (or tool) is the best for such task?
I was trying to write that using bash but codebase became quick very large and messy.
My target is unix platforms (especially Linux) - I'm thinking about Ruby or Python, but can I achieve such task with e.g. JavaScript/node?
Are there tools for something like that? I've heard something about Yeoman but I'm not sure if it is capable for my problem here.
Well since your question is too broad and you seem to be looking for a website generator, at least for Ruby here are the most obvious choices:
https://www.ruby-toolbox.com/categories/static_website_generation
All of them use templates, which I assume that will be usefull.
One of the most popular choice is the jekyll, which powers github pages
If none of them work for you, you can investigate their source code to create your own solution.
If you are going the rails way there's rails apps composer

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.

The better way to maintain css, js, font-cion, image's versions? [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 3 years ago.
Improve this question
I have few css files for a site and some css properties are shared through all of them. Plus there are also few js files. font icons file and images that I constantly updating. Whenever I tried to push to main repository, i had to make sure each file version are bumped using "?=number". I am seriously tired of doing this.
Is there a better way to do URL version bumps all together? Any help would be appreciated.
Additional info: I am using IIS7/8 and developing in windows system by using HG Mercurial. Back end uses asp.net visual basic, mysql.
Since you're using ASP.NET, your .NET devs can set a variable that holds a common increment number that you can use as the number in the ?v=number part. So, you just change all of your CSS/JS files to consume the variable one time only. For example:
string version = ConfigurationManager.AppSettings["VersionNumber"];
If you're using bundling, there is a better answer here:
How to make bundles unminify and list individual files when using a cookieless static content server?

Deploying my site, lots of small script files. Long loading time [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've built a web application.
In my application I have many javascript and css files .
They are separated based on my application's logic.
I am talking about close to 20 of these files (each file is 2 kb +-).
They seem to take quite a while to download (6 - 10 seconds altogether).
What would you do to cut down the download time? Are there any best practices in this field?
Thank you
Join all JavaScript and all CSS files into one big JS and one big CSS file, and minify them.
You can compress your file by removing spaces, use short variable names, etc. Try looking for tools that are around for that purpose. Also, you can add all scripting to one file so that only one files needs to be downloaded and you can introduce some caching mechanism to prevent downloading the script over and over again.
http://rakaz.nl/2006/12/make-your-pages-load-faster-by-combining-and-compressing-javascript-and-css-files.html
[http://driven-monkey.com/?p=97]
check these out

Categories

Resources