add image CSS : local file or url? [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 8 years ago.
Improve this question
I am working on a HTML Webpage with CSS and Ajax. I would like to add an image and I know I can do it by adding the image in a folder inside my project or add it with an URL so which one is better method to use, I mean what should be the inconvinients of each method that would make me prefer one to the other ?

You should have it in a local file because:
1) Relative paths;
2) You have more control on it (what if the other site is down?);
3) You don't have to read 1000+ pages of terms of use in which the external website may say that they will own your images if you put them there.
You should use external hosting because:
1) It is cheaper (sometimes free);
2) You can free up bandwidth (especially if you have a lot of images);
3) Using relative paths is not always better (and can cause issues with migrations, see the comment)
Deciding which one you would use depends on your needs. If you have few images, it is better to store them locally. If you have a lot of images and don't have the resources to host them, it is better to use external services.

Related

Using Content Delivery Network (CDN) hosting is better than host 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 3 years ago.
Improve this question
I'm developing web solution from a while and I've the feeling that most developers uses CDN links for sources rather than host JavaScript libraries or CSS styles files besides their pages.
Is it just a reason of space or are there any other reasons such as speed or anything else?
If CDNs are faster, how can it be possible that calling through an external link is faster than a local file on the same hosting?
I'd like to receive evidences of the pros and cons of CDNs, I am not asking for not opinion answers or preferences.
The reason for hosting files like that on a CDN is exactly the same as why you'd host any file on a CDN. A CDN has many nodes placed around the world that are likely to be much closer to an end user than your one web server. If somebody in Australia requests your website that's hosted in London you're going to have to send everything to them.
Alternatively you can host only the files you own, and leave the rest to a CDN. The CDN files are retrieved from a node closer to the user and your server only has to deal with your files. This reduces latency to your site and increases the chance that, if you're using a widely used library, a user might already have it cached.

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.

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?

Best way to organize javascript functions and 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
This title is giving me a warning about the question being subjective but I hope that's not the case.
Here's my situation: I have several functions(some are used on many pages, some only on one page) and I put them all into one .js file to save on load time. However, some pages run functions onload. For this to work, I need to have the functions file declared prior to the call. However, some of the functions require the page to be generated before it can grab the information it needs, so the file declare has to be at the end of the page. So right now, I've made two file declarations on the same page, for the same file. Looking in the console, this obviously causes problems as the first file can't get the information it needs, and throws an error.
So my question: Would it be best to break the functions in to two files (one pre-load one post?) or should the problem ones (which are functions unique to the page anyway) be hard coded at the top?
The best solution would be to break it into two files. That way you can reuse the code in more pages since the pre-load scripts work as they're supposed to, and the post-load scripts get the information they require. It would make the rest of you coding much easier.

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