简体   繁体   中英

Browser won't load file with .objjs extension due to MIME type

I've run this code in Chrome on my Windows 8 partition and in Firefox on my Ubuntu 14.04 partition. Both give me error messages related to MIME type.

   <head>
        <script type="text/javascript" src="resources/cube.objjs"></script>
    </head>

Note: The type doesn't seem to matter, I've tried type=text/javascript , type=application/javascript , type=javascript , and not type at all and I still get the same error messages.

The error message for Chrome on Windows is

Refused to execute script from http://localhost:63342/***/GraphicsTownJS2015-master/resources/cube.objjs because its MIME type ('application/octet-stream') is not executable, and strict MIME type checking is enabled.

And the error message for Firefox on Ubuntu is

The resource from http://localhost:63342/***/GraphicsTownJS2015-master/resources/cube.objjs was blocked due to MIME type mismatch (X-Content-Type-Options: nosniff).

Here's cube.objjs

var LoadedOBJFiles = LoadedOBJFiles || {} ;
LoadedOBJFiles["cube_ex.obj"]= {}
LoadedOBJFiles["cube_ex.obj"].vertices = [[0,0,0],[0,0,1],[0,1,0],[0,1,1],[1,0,0],[1,0,1],[1,1,0],[1,1,1]]
LoadedOBJFiles["cube_ex.obj"].normals = [[0,0,1],[0,0,-1],[0,1,0],[0,-1,0],[1,0,0],[-1,0,0]]
LoadedOBJFiles["cube_ex.obj"].texCoords = []
LoadedOBJFiles["cube_ex.obj"].groups = {}
LoadedOBJFiles["cube_ex.obj"].groups['cube' ] = {}
LoadedOBJFiles["cube_ex.obj"].groups['cube' ].vertices = LoadedOBJFiles["cube_ex.obj"].vertices
LoadedOBJFiles["cube_ex.obj"].groups['cube' ].normals = LoadedOBJFiles["cube_ex.obj"].normals
LoadedOBJFiles["cube_ex.obj"].groups['cube' ].texCoords = LoadedOBJFiles["cube_ex.obj"].texCoords
LoadedOBJFiles["cube_ex.obj"].groups['cube' ].faces = [[[0,null,1],[6,null,1],[4,null,1]],[[0,null,1],[2,null,1],[6,null,1]],[[0,null,5],[3,null,5],[2,null,5]],[[0,null,5],[1,null,5],[3,null,5]],[[2,null,2],[7,null,2],[6,null,2]],[[2,null,2],[3,null,2],[7,null,2]],[[4,null,4],[6,null,4],[7,null,4]],[[4,null,4],[7,null,4],[5,null,4]],[[0,null,3],[4,null,3],[5,null,3]],[[0,null,3],[5,null,3],[1,null,3]],[[1,null,0],[5,null,0],[7,null,0]],[[1,null,0],[7,null,0],[3,null,0]]]
LoadedOBJFiles["cube_ex.obj"].groups['cube' ].material ='null'

I'm running this code from the WebStorm IDE in both cases. Any ideas as to what I can do to fix this?

Here's the github page for the webapp that generates objjs files https://github.com/Squeakrats/OBJLoader

You can utilize fetch() to retrieve .objjs file, create a <script> element with .textContent set to promise value of .text()

window.onload = () => {
  fetch("resources/cube.objjs")
  .then(response => response.text())
  .then(obj => {
    var script = document.createElement("script");
    script.textContent = obj;
    document.head.appendChild(script);
    console.log(LoadedOBJFiles);
  })
}

plnkr http://plnkr.co/edit/WFDIhnsIjYJ8T8ExAdvj?p=preview

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM