Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9109435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:02:48+00:00 2026-06-17T03:02:48+00:00

I have seen the following question where someone asked how to remove shaders from

  • 0

I have seen the following question where someone asked how to remove shaders from html:
WebGL – is there an alternative to embedding shaders in HTML?

There are elaborate workarounds to load in a file containing the shader suggested in the answers to the question.

In the tutorial I saw, the shader code is embedded directly in the html.
The javascript code refers to it using getElementById. But it’s ugly embedding the shader directly in the html for many reasons. Why can’t I just refer to it externally using the src= attribute?

<script type="x-shader/x-fragment" id="shader-fs" src="util/fs"></script>

The above doesn’t work, I just want to know why not. This is clearly something to do with limitations on script itself, but I don’t get it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T03:02:49+00:00Added an answer on June 17, 2026 at 3:02 am

    You don’t have to use <script> tags at all to load a shader program. Most tutorials and examples just use them as a container to store a string in the DOM of the webpage. The script type "x-shader/x-fragment" is meaningless for web browsers, so they don’t execute the script. They do, however, store the content of that tag as a string in the DOM which can then later be accessed by “real” scripts. This only works when the script content is in the HTML file. When you load the script via a src attribute, the content does not become a text childnode of the script tag and thus can not be accessed through the DOM tree.

    You can just as well store the sourcecode for the shader as a string in a Javascript file:

    // myVertextShader.glsl.js
    var myVertexShaderSrc =         
            "attribute vec3 pos;"+      
            "void main() {"+        
            "   gl_Position = vec4(pos, 1.0);"+     
            "}"
        ;
    

    You would then compile the shader like this:

    var vertexShader = gl.createShader(gl.VERTEX_SHADER);
    gl.shaderSource(vertexShader, myVertexShaderSrc);
    gl.compileShader(vertexShader);
    
    gl.attachShader(program, vertexShader);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen the following question but I still have a few doubts. Sending
A small - little question. I have seen many application having buttons like following.
Can someone recommend a hosted solution that answers the following requirements (I have seen
I have seen the following tag as an answer to a question: <%: Model.FirstName
You may have seen my last question where I use the following to inject
I have seen this question asked several times but the answers have so far
From the following page (http://code.google.com/p/appengine-pipeline/wiki/GettingStarted) I have seen the following code in an example
So, this question has been asked lots, and i have seen many different answers,
I have seen many articles and Questions/Answers Regarding Lock Escalation but following things are
I have seen the following exception case several times public SomeClass(IEnumerable<T> someValues) { if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.