I'm writing a WebGL application. Until now I put my shaders in <script>
-tags right into my standard html file (let's call it index.html). So it was easy to just "parse" the shader-code by using .text
on the script-tags taken with getElementbyId('foo')
.
But now I think that's untidy. I want my shaders to be stored in external files with extension .vert
/.frag
and parse them from there. My first approach was the following:
<script id="shader-vs" src="./shaders/basic_vertexShader.vert" type="x-shader/x-vertex"></script>
<script id="shader-fs" src="./shaders/basic_fragmentShader.frag" type="x-shader/x-fragment"></script>
var shaderScript = document.getElementById(id);
if (!shaderScript) {
return null;
}
var str = shaderScript.text;
The result is an empyt string (""). I double checked if all file-paths are correct. It seems, that .text
only works for lokal tags.
So, what could I do, to receive the contents of that files? AJAX isn't a possibility, since the application should work without internet-connection, too, when it's saved on clientside's storage.
I'm thankful for every suggestion.
Important: As I mentioned I'm NOT searching for that usual AJAX-stuff. I'm searching for a possibility to get the code of external linked script-files. Since they are statically linke in the HTML-file, I thought this should be no problem without asynchrone requests. But it seems to be.