Playable Ads made with Defold? For Facebook Ads?


With Defold you can produce very lightweight and well-optimised builds, both mobile and HTML5 from the same sources.

One idea tickles my brain for the past few days - is it possible to produce Playable Ads with Defold? Playable Ads have self-explaining name - the ad you can play, technically they are tiny HTML5 games. I heard such ads have very good conversions rates, so just imagine - you build iOS/Android game and with cost of pressing few buttons also build a Playable Ad for it, from the same sources. Sounds intriguing!

And not so long ago Facebook added the ability to upload playables to their system. Here are requirements, some important points:

  • Playable should not require mraid.js.
  • A single file for playable ad that contains all assets as part of that single HTML file and assets should be data URI compressed. (Javascript, CSS, images, sounds).
  • Playable asset size should be less than 2 MB.
  • No dynamic asset loading through external network is permitted.
  • Tips for combining into one file-encode image into base64 string, integrate js into index.html.
  • Playable HTML5 should not contain any JS redirect.
  • Playable should not make any HTTP request.

I’m not very familiar with Defold’s HTML5 tech stack, is there any requirement impossible to reach with Defold?

1 Like

Embedding HTML5 build in a React.js component

A single file for playable ad that contains all assets as part of that single HTML file

Might be a little annoying to do manually if it is possible to do. Assuming it is you would probably also want to manually exclude WASM runtime.

1 Like


Manual job is not a big issue and any manual routines can be automated, the main question is if it’s possible at all.



Sure, it’s possible. You need to strip the engine from anything you don’t need, use texture compression and in general be very smart with the assets you use. And create a script that takes care of packaging the whole thing in a single .html file.



I’m back on this again. Ok, I see how to inline css and js into html-file, need to rework such pieces of code:

    function load_engine() {
		var engineJS = document.createElement('script');
		engineJS.type = 'text/javascript';
		if (Module['isWASMSupported']) {
		    engineJS.src = 'PlayableAd_wasm.js';
		} else {
		    engineJS.src = 'PlayableAd_asmjs.js';

That’s clear. But I don’t fully understand how Defold packs assets for HTML5, like images, fonts, sounds etc? Can’t find anything related in the docs. As I see there is archive folder:

and there is some JS code in index.html:

var extra_params = {
		archive_location_filter: function( path ) {
			return ("archive" + path + "");
		splash_image: "splash_image.png",
		custom_heap_size: 268435456,
		disable_context_menu: true

And I’m not 100% sure what it does… gives the reference to function returning path to file in archive… so, how can I inline this stuff into my resulting HTML? is it ever possible?



I’m not 100% sure of the process but I guess the code in dmloader.js needs to be modified to support loading from an embedded string.

We should add this as a bundle option.



Aha, I found where this path-function parameter is used in dmloader.js, later archive-files seem to be loaded via HTTPRequest. Code is not obfuscated or minified here, so I believe I can rewrite it to work as I need. I’ll put updates with the progress here, thanks!



Defold is too heavy for playable ad (in my opinion). PixiJS and any other lightweight JS engine are much better for this.

But I made the project as a demonstration that Defold can fit into one HTML file that less than 2mb.

Now you just need to do a playable ad and submit it to Facebook for approval :grinning:

If you succeed, I’ll make a complete asset out of this project.


Happy 2021!

Wow! It works! I’ve used it on “Linker” sample project, there is a resulting one-html-file, it weights 2.4mb and canvas scaling need to be fixed, but in common script worked like a charm, thanks!

The only thing was to change “projectTitle” in “gulp file.js”



Update: I’ve missed two additional things:

  • add embed=“compressed” in html template (already fixed in repo by @aglitchman)
  • set app manifest in project settings

So after doing this the resulting html is 1.85mb! success!

Now going to try it on my “real” game…



Great! Very nice work on this! What if you apply texture compression on the assets as well?



I’ve removed all sounds and music, throw away some sprites to reduce the size of atlas and came up with 2.4mb build size. Then played around with compression settings in texture_profile but this did not show a significant changes, but limiting the “Max Texture Size” did the trick (and as for 2mb ad the resulting quality is ok imo) - 1.99mb :grinning:

Here is the link: - it’s a full game currently, just without sounds. So as for ad there is still some assets to be stripped.

And Facebook Ads manager “eats” the resulting HTML:



I’ve updated the project:

  • Added info on how to use it in your game
  • Added comments in the html5 template
  • Added compression for archive data
  • Now 7-zip is used for deflate compression
  • And so on…


Hey-hey, first playable ad is approved and live!

You can check it in the Facebook Feed by this link: (seems to be working only in FB mobile app; and I don’t know for how long the link will be working)

But I’ve noticed some major FPS drops in it and probably right now the ad does not provide a good user experience because of lags. So I need to check this.

UPD: fixed lags by setting “Contact Impulse Limit” in physics settings



The first test with Playable Ad finished, so, just want to confirm, that it was not banned or reported by users or something else, and for sure it was successful for the game:

“Results” here are “App Installs”, on iOS, in USA. You can see, that Cost Per Install was TWICE lower in comparison with a simple video on the same audience and placements! Well, my best CPI with video ad was around $0.7, so if be more precise, the win from playable ad was “only” 50% and not 100%. But still - very promising and inspiring!


Back to Defold after 2 years, "Bouncy Catapult" hypercasual prototype

You should make a post for this as its own thread as I was trying to find it and could not on my own! (Thank you to @d954mas for linking)

Using something like this also has other benefits…



Just in case - this still works with Editor 1.2.167.
But few minor changes to the engine_template.html required, as it changed during past year.



HI! Still works? Can you share the engine_template.html?