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

  • Home
  • SEARCH
  • 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 4624902
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:11:46+00:00 2026-05-22T03:11:46+00:00

I am currently developing a WebGL-based application, and I am having some trouble with

  • 0

I am currently developing a WebGL-based application, and I am having some trouble with shader storage…

I see in most examples that shaders are written in plaintext in the xHTML file itself. However this clutters the file and does not allow caching. Also, it’s not convinient to edit and reuse them. Having one file per shader is the best for organization. I can still insert them, with PHP, in the generated output, but it increases the size of the pages and can’t be efficiently cached.

Another solution is to fetch every shader with XmlHttpRequest, but I’m afraid the number of HTTP requests for a fresh page load (especially when you have dozens of shaders!) might quickly become a performance issue.

Finally, I’ve been thinking about dynamically putting all the shaders in a file, then loading it with a XmtHttpRequest. It’s only one request, for one file that can be cached locally by the browser. Yet, my JS is not that good and I don’t know how I should do it. I would build the file from the shaders in PHP, and extract them in Javascript.

But how ? I’ve been thinking about using XML or JSON to store headers in the big file, and I’d like help about the Javascript code to extract them. Thanks!

My PHP-generated shader file would look like this :

<vertex-shader id="shaderA">
    …shader code…
</vertex-shader>
<fragment-shader id="shaderB">
    …etc…
</fragment-shader>

Or :

{ "vertexshaderA": "…shader code…",
  "fragmentshaderA": "…etc…" }
  • 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-05-22T03:11:46+00:00Added an answer on May 22, 2026 at 3:11 am

    You can use the PHP JSON library. Read in all the shader files, then create an associative array out of them and use the json_encode function to create a JSON object.

    $arr = array ('vertexShaderA'=>code,'vertexShaderB'=>code);
    echo json_encode($arr);
    

    Then use XmlHttpRequest in JS to fetch the JSON object. Or use PHP to generate a JS file that sets a global (e.g. echo "Shaders =", json_encode($shaders)) and include it using a <script> tag.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently developing an application that needs to parse some (a big file of)
I am currently developing a Rails application using a database that was designed before
I'm currently developing a PHP application that's using an Access database as a backend.
I'm currently developing an application that is comprised of five separate executables that communicate
Im currently developing a Silverlight application that connects to an old webservice. Our old
I'm currently developing a web application for a particular niche. The point is that
we're currently developing an application that makes extensive use of popup windows(*) and have
We are currently developing Sliverlight 4.0 based web application using PRISM 4.0 for Sliverlight
Currently developing an application for Windows Phone that makes use of the bing maps
Im currently developing a MVC application Framework and I have come for some advise

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.