PlayCanvas engine asset loading problem

I’m using playcanvas engine only to build and maintain our application.
The problem is the engine use url string to decide type of resource.
It would be great the type is decided with its content type shipped with http response header.

In my case, all the assets are loaded from the backend server and their url format is ended up with *.do (after excluded query strings)

So I had to change ModelHandler constructor as below.

    constructor(device, defaultMaterial) {
        this._device = device;
        this._parsers = [];
        this._defaultMaterial = defaultMaterial;
        this.maxRetries = 0;

        this.addParser(new JsonModelParser(this._device), function (url, data) {
            return (path.getExtension(url) === '.json');
        this.addParser(new GlbModelParser(this._device), function (url, data) {
            return (path.getExtension(url) === '.glb' || path.getBasename(url) === '');

Also, I need to modify AnimationHandler.load function as below.

    load(url, callback) {
        if (typeof url === 'string') {
            url = {
                load: url,
                original: url

        // we need to specify JSON for blob URLs
        const options = {
            retry: this.maxRetries > 0,
            maxRetries: this.maxRetries
        console.log("Animation Handler > url : ",url);
        if (url.load.split('?')[0].endsWith('') || url.load.startsWith('blob:') || url.load.startsWith('data:')) {
            if (path.getExtension(url.original).toLowerCase() === '.glb') {
                console.log('response type is set to array buffer.');
                options.responseType = Http.ResponseType.ARRAY_BUFFER;
            } else {
                options.responseType = Http.ResponseType.JSON;

        http.get(url.load, options, function (err, response) {
            if (err) {
                callback("Error loading animation resource: " + url.original + " [" + err + "]");
            } else {
                callback(null, response);

There are comple more parts I’ve modified to load textures and materials.

So, I just wonder why playcanvas engine doesn’t use content-type from response header instead of paring url.

Hope this can be considered for the next update.

Hi @sooyong_Kim,

That makes sense, I think, you can try and post a feature request about it in the engine repo:

Potentially you can create your own resource loader where you convert the raw resource data to resource instances based on the content type, instead of the url extension. I don’t have an example in mind for that though, but you can study how the engine does that:

I believe it’s because using the extension is more fault tolerant to server setups than using the content type.

Flipping the question, why are you using .do instead of .glb?


The backend server is based on spring framework and .do is the default.
I know I can easily change or add .glb but anyway I need to parse the url to work with existing handlers.
That is why I hoped that it also checks the content type from the response header :slight_smile: