Showing posts with label Web Site. Show all posts
Showing posts with label Web Site. Show all posts

Tuesday, 27 March 2018

Prevent CSS and Javascript caching

Quite often, during the early days of a web site's/application's life, a developer can make minor corrections to JavaScript and CSS, whether to correct an issue, or in response to customer feedback.
Unfortunately, nearly all browsers cache these files to facilitate faster loading times during a revisit to a site. Whilst this is desirable for normal day to day use, it can be a developer's nightmare as they have to let the users, if known, know to refresh their cache, or if unknown, find another way to communicate this message.
However, there is a way around this.

The answer is known as using a phantom query string. Like requests for HTML pages, it is possible to append a query string to the references of the scripts and stylesheets. If these are unique on each call, then the file is reloaded from the internet, rather than the cache.
To accomplish this, it is as easy as adding a date and time stamp to the query part of the reference:
e.g.

    <script src="Scripts/script.js?636577391632578321"></script>
    <link href="Styles/style.css?636577391632578321" rel="stylesheet" />

If this date and time stamp is refreshed on each page load, then we can ensure that the file is also refreshed.
To accomplish this in PHP, we can use code like this:

    <link href="Styles/style.css?<?php echo time(); ?>" rel="stylesheet" />

Whereas in ASP/MVC, this will accomplish a similar task:

    <link href="Styles/style.css?@DateTime.Now.Ticks" rel="stylesheet" />

Use the same technique for JavaScript files.

Friday, 23 August 2013

New web site is up

I have completely failed to keep you all up to date with the latest development news from me.
A few days ago, my new games development web site went live. Even if I do say so myself, I think it's pretty cool. The entire site is coded by hand (apart from the Lightbox scripts). I prefer to create my own sites this way, so that I have total control over the content, without relying on, or being limited by, a third party content management system.
Anyway, if you want to have a look (and I know you do), then hop on over to: http://www.krazypengwin.com.
Second bit of news, probably not as impressive, but I think it is equally important, I have made some changes to the Colour Code Generator I mentioned before. It is now possible to drag and drop colours from the custom colours to the main colour button, and vice versa. It is also possible to use drag and drop to reorder the colours in the custom section. A little more important, I have added the possibility to drag and drop a colour from the application directly to the source code, and it will insert the colour, in the format selected, into your code. Not a massive change, but it could be useful and save a few seconds, rather than having to click Copy and then Paste. Some more formats have also been added, so the colours can now be formatted for the following languages: Monkey, BlitzMax, Xojo, Cocoa for OS X, Cocoa for iOS, Lazarus (and Delphi), Python, HTML, CSS and as either a list of decimal or hexadecimal values.
This little tool, along with some of the others I have written, will be available from my web site once I have written the help documentation.