# After using gltf-transform to compress the model, do we have to do this?

**URL:** <https://forum.babylonjs.com/t/after-using-gltf-transform-to-compress-the-model-do-we-have-to-do-this/48364>\
**Category:** Questions\
**Created:** [February 28, 2024, 12:19pm UTC](https://forum.babylonjs.com/t/after-using-gltf-transform-to-compress-the-model-do-we-have-to-do-this/48364 "2024-02-28T12:19:20Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![tiger\_yang](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tiger_yang/32/33056_2.png) [@tiger\_yang](https://forum.babylonjs.com/u/tiger_yang)\
**Post date:** [February 28, 2024, 12:19pm UTC](https://forum.babylonjs.com/t/after-using-gltf-transform-to-compress-the-model-do-we-have-to-do-this/48364/1 "2024-02-28T12:19:20Z")

</div>

I used the gltf-transform plugin to optimize the model, and the command was:

```auto
gltf-transform optimize car.glb car_1.glb --compress meshopt --texture-compress webp --texture-size 512

```

It works fine on a computer, but when embedded in ios as a webview, it gets an error.  
the error: “error:[https://cdn.babylonjs.com/meshopt\_decoder.js](https://cdn.babylonjs.com/meshopt_decoder.js)”

I learned that with the meshopt algorithm, bjs has to load the plugin, so I added this code！！！

```auto
 const engine = new Engine(canvas, antialias, engineOptons, adaptToDeviceRatio);

    MeshoptCompression.Configuration = {
      decoder: {
        // default is the CDN path, I changed it and use my local files
        url: "javascripts/meshopt_decoder.js" // the path of my local file
      }
    };
    const scene = new Scene(engine, sceneOptions);

```

There don’t seem to be too many examples of meshopt, should I do this?  
Or is there a better compression than **meshopt** to optimize the model **on the mobile**?

thank you.！！！

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [February 28, 2024, 9:25pm UTC](https://forum.babylonjs.com/t/after-using-gltf-transform-to-compress-the-model-do-we-have-to-do-this/48364/2 "2024-02-28T21:25:25Z")

</div>

This should work, not sure why it would not change the url.

cc @RaananW and @bghgary

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [February 28, 2024, 10:45pm UTC](https://forum.babylonjs.com/t/after-using-gltf-transform-to-compress-the-model-do-we-have-to-do-this/48364/3 "2024-02-28T22:45:09Z")

</div>

This sounds like a WebView problem. I don’t have much experience with using WebView on iOS, but from a quick look at documentation, it really depends on how you loaded the page. For example, if call [loadHTMLString](https://developer.apple.com/documentation/webkit/wkwebview/1415004-loadhtmlstring), there is a `baseURL` parameter that determines where the local files are loaded from. If you call [loadFileURL](https://developer.apple.com/documentation/webkit/wkwebview/1414973-loadfileurl), there is an `allowingReadAccessTo` parameter. How are you loading your WebView?

---

<div class="post-metadata">

**Author:** ![tiger\_yang](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tiger_yang/32/33056_2.png) [@tiger\_yang](https://forum.babylonjs.com/u/tiger_yang)\
**Post date:** [February 29, 2024, 12:50am UTC](https://forum.babylonjs.com/t/after-using-gltf-transform-to-compress-the-model-do-we-have-to-do-this/48364/4 "2024-02-29T00:50:40Z")

</div>

But I’m sure that if I didn’t optimize the model with gltf-transform, there would be no errors on ios

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [February 29, 2024, 1:28am UTC](https://forum.babylonjs.com/t/after-using-gltf-transform-to-compress-the-model-do-we-have-to-do-this/48364/5 "2024-02-29T01:28:57Z")

</div>

Right, optimizing with `meshopt` requires the loader to load the meshopt extension which must load the meshopt library from separate js/wasm files. If you don’t optimize with `meshopt` or `draco` then you don’t need the separate files.

---

<div class="post-metadata">

**Author:** ![tiger\_yang](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tiger_yang/32/33056_2.png) [@tiger\_yang](https://forum.babylonjs.com/u/tiger_yang)\
**Post date:** [February 29, 2024, 1:47am UTC](https://forum.babylonjs.com/t/after-using-gltf-transform-to-compress-the-model-do-we-have-to-do-this/48364/6 "2024-02-29T01:47:07Z")

</div>

After testing and comparison, we found that the optimization result of meshopt is very good. Of course, I do not want to load additional plugins, because I think loading plugins on the mobile terminal will always affect the performance or loading speed. Is there any other better optimization scheme?

---

<div class="post-metadata">

**Author:** ![tiger\_yang](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tiger_yang/32/33056_2.png) [@tiger\_yang](https://forum.babylonjs.com/u/tiger_yang)\
**Post date:** [February 29, 2024, 1:53am UTC](https://forum.babylonjs.com/t/after-using-gltf-transform-to-compress-the-model-do-we-have-to-do-this/48364/7 "2024-02-29T01:53:45Z")

</div>

And I also learned that **android** loading external files seems to be not allowed, like this loading external js files, will there be a problem.

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [February 29, 2024, 11:24am UTC](https://forum.babylonjs.com/t/after-using-gltf-transform-to-compress-the-model-do-we-have-to-do-this/48364/8 "2024-02-29T11:24:39Z")

</div>

From your message I can’t seem to understand if it worked once you used the local file instead of the CDN. Does it work locally? (And sorry if I missed something!)

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [February 29, 2024, 4:31pm UTC](https://forum.babylonjs.com/t/after-using-gltf-transform-to-compress-the-model-do-we-have-to-do-this/48364/9 "2024-02-29T16:31:52Z")

</div>

> [@tiger\_yang](#):
>
> Is there any other better optimization scheme?

It depends on what you are doing with the model. A lot of times, simply doing quantization makes a big difference. Quantization does not require additional libraries. Meshopt or Draco will compress more but it may not give a huge difference.

---

<div class="post-metadata">

**Author:** ![tiger\_yang](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tiger_yang/32/33056_2.png) [@tiger\_yang](https://forum.babylonjs.com/u/tiger_yang)\
**Post date:** [March 4, 2024, 2:54am UTC](https://forum.babylonjs.com/t/after-using-gltf-transform-to-compress-the-model-do-we-have-to-do-this/48364/10 "2024-03-04T02:54:25Z")

</div>

Yes, there is an error when using the CDN in the app

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [March 4, 2024, 9:16am UTC](https://forum.babylonjs.com/t/after-using-gltf-transform-to-compress-the-model-do-we-have-to-do-this/48364/11 "2024-03-04T09:16:54Z")

</div>

So it does work locally - a perfect solution TBH.

would be very interesting to understand why the CDN file didn’t work. I believe @bghgary discussed that in his first answer.
