You need to sign in to do that
Don't have an account?
CDATA not being procesed correctly
I have a visualforce page with this code:
When I load the page up I get this:
This is obviously incorrect and a bug. The content type is application/javascript and the output is outputting XML. The output should be the CDATA contents.
<apex:page contentType="application/javascript"> <![CDATA[ for (var i=0; i < 5; i++) { console.log('Hello World'); } ]]> </apex:page>
When I load the page up I get this:
<![CDATA[ for (var i=0; i < 5; i++) {]]><![CDATA[ console.log('Hello World');]]><![CDATA[ }]]><![CDATA[ ]]>
This is obviously incorrect and a bug. The content type is application/javascript and the output is outputting XML. The output should be the CDATA contents.
This is odd, I was unable to get it to work in anyform. In order to get this actually looked at as a bug you will need to contact Salesforce support directly. Personally I would not use Visualforce to generate your javascript files because of the additional overhead. I would put them in a static resource and reference them that way.
The reason why I need it to be in a Visualforce page is it is being requested from a Web Worker and I need dynamic values to be filled in. Visualforce Pages seem to have trouble with content type Javascript since the source code often contains < and &. CDATA would solve this issue except that SF is doing something odd/wrong with it so I wanted to bring this to the attention of the community.
Another bug I just noticed is that my carriage returns are being replaced with a space. This also is wrong CDATA handling.
For now while Salsforce is fixing their bug I am going to use a workaround I came up with. Instead of the CDATA tags I will use //<script> at the top and //</script> at the bottom.