Web design practices to minimize browser refresh [duplicate] - javascript

This question already has answers here:
How can I force clients to refresh JavaScript files?
(30 answers)
Closed 2 years ago.
The design of our website is such that whenever we make some changes in CSS & JavaScript files we require the user to clear the browser cache and get the latest version of these files from the server. This is highly undesirable from the user perspective and I don't see well designed websites out there having this issue.
Are there any website design best practices that can be followed to minimize this issue? Any pointers would be appreciated.

Check out more on cache-busting. When you make changes to your css and javascript, you can append a version type to force the browser to reload the document.
Example:
<script src="myjavascript.js?v=1.1"></script>
<script src="myjavascript.js?v=1.2"></script>
etc : )

Related

How to Use Multiple CDN for Library Scripts? [duplicate]

This question already has answers here:
Best way to use Google's hosted jQuery, but fall back to my hosted library on Google fail
(23 answers)
Closed 5 years ago.
I want to use both "Google Hosted Libraries" and "Microsoft Ajax Content Delivery Network" for library scripts like jQuery, so that even if one fails to load (e.g. Google), another one is loaded, and the webpage is rendered correctly.
Since Google is banned in China and in some other regions, it is necessary to add backup sources like Microsoft/CDNJS or local files.
Please note that my jQuery is at the bottom of the page, not in the head.
Could you please give me a reliable solution? It'd be great if it's loaded in the following order:
Google>CDNJS/MICROSOFT>Local File
This question is not duplicate! I didn't find any reliable/specific solution for this issue.
Insert the following javascript right after your initial script tag.
<script src="http://code.jquery.com/jquery-2.2.4.min.js"></script>
<script type="text/javascript">
(window.jQuery)||document.write('<script type="text/javascript" src="/scripts/jquery-2.2.4.min.js"><\/script>');//]]>
</script>
Explanation:
Try load the jQuery script from a cdn
If that fails load a fallback script from js
Note: replace the url with your preferred fallback url

Difference between using local JS and JS from CDN [duplicate]

This question already has answers here:
What are the advantages and disadvantages of using a content delivery network (CDN)? [closed]
(4 answers)
Closed 7 years ago.
I am trying to write a JavaScript script to populate HTML using jQuery and Bootstrap. In many tutorials on the internet, tutors mention to using files from a Content Delivery Network(CDN) instead of calling those files locally.
But I am unable to foresee any advantage making a call to js or CSS over a network, instead of loading it locally, which should prove good enough.
I am eager to know, what is the difference in terms of network and machine resources as well as the load on a page.
Pros using CDN:
* cache for the library in the client side.
Cons using CDN:
* If the cdn's site is down, your site will not get the files.
* Cdn file changes frequently and therefore your production site will work with the newest files that you didn't checked them(this can be very dangerous).
Now you can think if this suitable for your site.

Should I be concerned if my website is linked to an external Style Sheet [duplicate]

This question already has answers here:
Why should I use Google's CDN for jQuery?
(7 answers)
Closed 7 years ago.
At some point in my website I needed a Timer so I looked for a free jQuery Countdown Timer and found this one : Example
After integrating the model to my page inside my IDE (VS2010) i payed attention that some CSS and JS files are not stored locally in my project folder, but they are still Linked to an External sources, and that had me thinking : Am i suppose to find a way to download these file locally than use them, or should i use them the way they are ? and should i be concerned if they may change or desperate at some point in the future ? what are the best practices in case ?
Here is an example of the HTML code :
....
....
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<script type="text/javascript" src="inc/TimeCircles.js"></script>
....
....
Those are CDNs ( http://it.wikipedia.org/wiki/Content_Delivery_Network ) meaning that they're hosted by someone for all of us to use, so you're pretty much guaranteed it will stay there. The main advantage of using CDNs is that the user will probably have visited another site that uses the same resource and this means that said resource is already cached in the user's computer, leading to a faster loading time for your site.
You should never rely on external sources for critical files unless you're using a dependable CDN. In this case you're using the most common CDN sources for Bootstrap and jQuery, so you're all set.
I assume that you've downloaded the timer files and are hosting those locally. Your reference to them confused me, so I've updated this answer.

I want to make php Application standalone [duplicate]

This question already has answers here:
Convert a PHP script into a stand-alone windows executable
(7 answers)
Closed 9 years ago.
I want to make windows standalone app with php, even i want to use database, javascript in that application.
Note : i don't want to give source code to user.
I should be like exe file which user can run.
If going with Windows, try WinBinder. It allows you to develop native Windows applications using PHP.
It also supports SQLite, so you don't need a database server
Also this answer will help you
I use phc to create .exe files out of my PHP source code. It works quite well, but it's mostly good for console applications rather than full webpages.
However, you could have your PHP script include a basic "server" that allows the browser to communicate with it - I have done this in the past too, and while it might seem daunting the results were very rewarding.

How to screenshot website in JavaScript client-side / how Google did it? (no need to access HDD) [duplicate]

This question already has answers here:
Using HTML5/Canvas/JavaScript to take in-browser screenshots
(7 answers)
Closed 5 years ago.
I'm working on web application that needs to render a page and make a screenshot on the client (browser) side.
I don't need the screenshot to be saved on the local HDD though, just kept it in RAM and send it to the application server later.
I researched:
BrowserShots alike services...
Mechanized browsers...
wkhtmltoimage...
Python WebKit2PNG...
But none of those gives me all I need, which is:
Processing at browser side (generate screenshot of page). Don't need to be saved on HDD! Just...
...send image to Server for further processing.
Capturing whole page (not only visible part)
Eventually I came upon Google's Feedback Tool (click "feedback" on YouTube footer to see this). It contains JavaScript for JPG encoding and two other huge scripts which I can't determine what exactly they do...
But it's processed on the Client side - otherwise there would be no point putting this huge JPEG encoder in the code!
Anyone have any idea how did they made it / how I can make it?
Here is an example of the feedback (report a bug on some screens)
This answers your problem.
You can use JavaScript/Canvas to do the job but it is still experimental.
Update:
There is a library for this now https://html2canvas.hertzen.com/
I needed to snapshot a div on the page (for a webapp I wrote) that is protected by JWT's and makes very heavy use of Angular.
I had no luck with any of the above methods.
I ended up taking the outerHTML of the div I needed, cleaning it up a little (*) and then sending it to the server where I run wkhtmltopdf against it.
This is working very well for me.
(*) various input devices in my pages didn't render as checked or have their text values when viewed in the pdf... So I run a little bit of jQuery on the html before I send it up for rendering. ex: for text input items -- I copy their .val()'s into 'value' attributes, which then can be seen by wkhtmlpdf

Categories