Html5 Slot Machine Game
Imagination really is the only limit! Have your own HTML5, pure Javascript slot machine on your site! In a recent survey, 74% of users said the well finished game contributed “moderately or significantly” to the fun of the site. Packages provide a license for you to use this slot machine on all your sites.
This is the fourth part of the Slot machine game in HTML5 (previous parts 1, 2, and 3) and this time we modify the game to support HTML5 offline mode, also known as HTML5 Application Cache.
Try out offline supported version here.
Free Offline Slot Machine Games
Word of warning. HTML5 offline mode is powerful but very fragile feature. It’s tricky to get right, but once you get it to work the mobile user experience can be very native app like.
Some problems you will encounter
- Browser refresh logic is confusing. Especially the fact that browser does not use updated manifest and resources when they change but only after next reload. Fortunately Javascript workarounds exists.
- Application cache file maintenance needs diligence. For example, browser will not reload any assets if this file is not modified.
- Externally linked resources do not generally work offline. This makes CDN use difficult.
- Web server has to use right MIME type and cache settings to reliably use application cache files. Most web servers don’t do this in default configuration.
- No reliable way to detect if page was loaded in online or offline mode.
- Chrome bypasses some restrictions (e.g. cross-domain issues) in the specification and what works in Chrome may not work anywhere else.
- Each browser has slightly different meaning and heuristic for using offline mode. For example if browser can load some unrelated pages but can’t currently load your app page it may not show your page in offline mode and simply shows “Can not reach the server error”. This may happen especially if it knows from last load that manifest has been updated. Then at other times, it may load page few times in offline mode even when connectivity has returned.
Manifest file
Web page must use application cache manifest file to support offline mode. This manifest file is specified in html tag of the page.
The file has listing of all content that page needs. For detailed explanation of each section, refer to Beginners guide to HTML5 application cache
Web Fonts
Slot Machine Script
Web fonts must be hosted locally if you want to use them offline. Note that some web fonts may have licensing restrictions for local hosting.
The webfont.css
defines the font face and loads true type file.
The file Slackey.ttf
is hosted locally in css
directory.
Web Server Support
Web server must use correct MIME type for text/cache-manifest
application cache manifest. For example, in NGINX web server edit the mime.types
and add following file type to MIME type mapping.
Browsers should check manifest every time page is loaded online, but it may not do this often enough if cache control is too long. Therefore, set short cache lifetime for the manifest files by adding this inside server
section of NGINX configuration file. This forces cache lifetime of 1 minute to all *.appcache
files.
Verify with cURL that server response Content-Type
has right MIME type and that the Expires
and/or Cache-Control
have correct 1 minute cache life time. If you get 404 error, make sure that site root configuration is set in http
section.
Detecting online status
Currently only “reliable” method to do is to make Ajax request and check the response. There are some caveats
- Request may fail for other reasons, and this does not mean browser is in offline mode
- Offline status may change while user is in page, you may want to do repeat polling check.
- User may be in public WiFi that redirects requests to login server. This can confuse your app that gets response but is not what was expected.
Slots game checks online status in parallel while game loads and only on startup. Slots game does not really need to know if it’s online or offline, but just writes the status on screen for debugging purposes.
Otherwise loading images, audio and other content should be fully transparent to your app. Think twice before doing separate logic for online and offline as things will get difficult. Best advice I can give is to that you write code for online use with proper handling for Ajax errors. In this way when app loads in online mode but loses network later in session (e.g. when user goes in subway tunnel), the experience does not break completely.
Testing
This is the part where things get interesting, offline is tricky to test because of caching and browser reload logic. See detailed lamentation about subject here in Dive into HTML5.
These are the best practices I’ve come up with. First, set browser manually to offline mode to try things out. e.g. in Firefox this is enabled from File->Work Offline.
Second, if you develop the game from local server, do not use http://localhost
as host, but use real domain name that resolves to localhost. In this example I’ve used http://hexxie.com
that supports wildcard subdomain. Any subdomain resolves to address 127.0.0.1
.
In this way you can always start from scratch the offline debugging simply by changing subdomain name. For example I just used slotsoff1.hexxie.com, slotsoff2.hexxie.com, … etc.:
Note that at least Firefox asks each time if you allow offline content.
Before each deploy, remember to increment the version comment in manifest file, so web server notices that the file has changed and browser will refresh it on next load. Server does not look inside the manifest file, so it does not matter how you change the file, as long as it’s changed.
Good Luck!
Code is available in Github.
Examples
Overview
Summary
Visitors increasingly want to engage with our sites and brands. This slot machine gives the perfect way for your visitors to do that with little effort or cost to you or your company. On top of that it increases customer loyalty, returning to the site to continue to play! We've seen a huge variety of companies use this to great success. Imagination really is the only limit!
Have your own HTML5, pure Javascript slot machine on your site! In a recent survey, 74% of users said the well finished game contributed “moderately or significantly” to the fun of the site.
Packages provide a license for you to use this slot machine on all your sites. You can mix it up and customize your slot machine with the 5 different pre-set designs provided, or you can very easily make your own.
Written in pure HTML 5, Javascript, jQuery and CSS it is extremely quick and simple to integrate into any new or existing site. Proven to work flawlessly on mobiles and tablet (including Android, iOS and Windows Phone), your visitors can enjoy this feature at any time and there is no use of Flash or Java, so no annoying pop ups to distract your visitors from what you want them to focus on!
Some interesting uses and ideas for your slot machine
These are some of the imaginative uses our customers have given their slot machine. Get your creative juices flowing!
- Encourage spending in your store giving people a chance to win discounts, prizes and promotions.
- Give credits away as virtual game currency, or virtual goods in those games, when users level up, or find a chest, for example.
- Give customers a chance to win a discount at the time of checkout, in your online store.
- Use it together with physical scratchcards to give people prizes in a loyalty program.
- Set up a spot at events with several games to entertain guests.
- Add casino-style games to your site, to increase customer engagement.
- Create a buzz at a convention, letting visitors play and win merchandise items (t-shirts and hats, for example). Change the odds heavily so that almost everyone wins.
Features
- 5 designs included, immediately ready to use.
- Fully customizable. You can very easily change the images, sounds, animations, pay table, and prizes to suit your needs.
- Completely responsive to every resolution and device. Works on every browser.
- You can offer either monetary prizes, or physical gifts like hats, t-shirts, or store credit for your site, to improve your brand and keep customers coming back!
- 100% HTML, CSS3 and Javascript code, based on jQuery. Does not use Java or Flash, ensuring compatibility with all mobile devices.
- Smooth jQuery animation.
- Cheat and fraud prevention measures to avoid getting fraudulent complaints from your customers.
- Over 10 million spins to date, resulting in millions of dollars in profits for the different sites that host it. On a monthly average, there's about one spin every 5 seconds.
Package
The package includes the full source code for the entire slot machine, including HTML, CSS, Javascript and PHP code. It also includes extensive documentation on how to implement the slots in your own site, and how to customize every element of it, in case you want to.
Only a very, very basic knowledge of PHP and CSS is necessary to add this to your site. If you don't have your own programmers, or don't feel comfortable doing it, we can do this for you for a fee.
We also offer a custom-design option for an extra fee, in which we get you in contact with our graphics designer, and you get the design that you need, ready to plug into your site.
Buy this slot machine today, or contact us with any questions.
F.A.Q.
- Can I change the icons to my products / company logo?Open or Close
Yes, all the images you see can be directly replaced for anything you would like, by simply changing the files provided.
- Can I customize the odds of winning / the game's payout / my profit margin?Open or Close
Yes, all the probabilities are 100% configurable when setting up the prizes for the game. This is explained in detail in the documentation, including examples to make it as easy as possible.
- Can I use this slot machine in my Wordpress site?Open or Close
Yes, it's quite easy to integrate this into Wordpress by simply modifying the site templates to add the HTML code, and then adding the extra CSS and JS file. Quick and simple!
- Can anyone implement this?Open or Close
A very minimal knowledge of PHP and CSS is needed to implement this on your site. Any junior programmer can do it. Alternatively, you can hire us to do it for you, for a very small additional fee.
- Is it a one-time payment?Open or Close
Yes, a one time payment of the license fee gives you our full source code, and allows you to use the slot machine in as many sites as you own.
- How can I customize this slot machine?Open or Close
You can very easily change everything that your visitors will see about the slot machine. All images and sounds, the pay table configuration, maximum and minimum bets, payouts, the details of the animation, etc. The package you will buy includes extensive documentation on how to modify all of these, and our support team will also be able to help you and answer all your questions.
- Can I have non-monetary payouts?Open or Close
Yes, several of our customers use their slot machine to give out t-shits, hats, store credit, discount codes and more!
- Can monetary payouts have cents?Open or Close
Yes, you can have your payouts in entire dollars, quarters, cents, even Bitcoin fractions if you want.
- Does it work with Bitcoin / Litecoin / other cryptocurrencies?Open or Close
Yes! Basically, you can integrate this with any payment / credits mechanism you can think of, be it regular money, Bitcoin, tokens, anything!
- Do I get the full source code?Open or Close
You get absolutely everything, in full un-minified, non-obfuscated form. All the PHP, HTML, CSS and Javascript, which you can modify as much as you wish, along with extensive documentation on how to do so.
What our previous customers say
'The customers love it'
We installed the slot machine software on our website about six months ago and could not be happier. It was super smooth and we have not had to return to Daniel even once with any problems - in fact not one of our customers has ever reported a problem with a spin which is amazing for a web based game. The integration was a snap and putting our own custom design into the machine was much easier then expected. We could not be happier with the entire experience and our customers love playing every day.
'Huge increase in customer engagement'
From start to finish Daniel was the perfect man for the job. We were setting up a fun virtual games website and communicated a few game ideas to Daniel. The animations were smooth, the games felt fast, and they were able to handle a large number of users.
Our customers were consistently thrilled with the way the games worked, and the games were a big success immediately after launch. In a recent survey 74% of users said the well finished games he programmed contributed 'moderately or significantly' to the fun of the site.
'Only took me about half an hour to integrate.'
I love your coding style, very organized and well documented. Only took me about half an hour to integrate with our systems, works great and our users are LOVING it!
'I highly recommend Daniel's work.'
I found Daniel to be an extremely knowledgeable and reliable developer who helped us integrate his games into our retail platform. Daniel made himself available for our questions and gave assistance whenever we requested.
I highly recommend Daniel's work to anyone who wishes to be successful the first time out. His insight is invaluable.
'Very easy to customize, works in all browsers'
The slot machine is working really well – we haven't had any reports of problems from players, many of which are using tablets / smartphones.
The documentation was great and the code well laid out and self-explanatory making any customisations easy to add into the code..
'Very professional service'
Daniel is a true professional that provides exceptional value. He kept his word on both pricing and beat his estimated delivery time. I definitely will be working with him on projects in the future.