I am using JavaScript Lint in vim. Recently I converted my pure JavaScript to php so as to make certain server side additions. I have set the file type in vim as such :s filetype=javascript.php.
test.php:
/*jsl:ignore*/
<?php
header("Content-type: application/x-javascript");
?>
/*jsl:end*/
function foo() {...}
I get a syntax error at <?php, both in vim and online. I guess jsl:ignore ignores warnings, but not syntax errors, and it is detecting <?php as a syntax error. Is there anyway to bypass this as it is essentially a deal breaker for JavaScript Lint.
EDIT There have been a great number of requests as to what it is I am doing, therefore, here is a more thorough explanation.
I have a database for my pictures, like so
ID owner path
0 0 /var/www/0/*.jpg
1 0 /var/www/0/*.jpg
2 1 /var/www/1/*.jpg
3 2 /var/www/2/*.jpg
4 0 /var/www/0/*.jpg
The important thing here is that there is absolutely no correlation between the picture ID and/or who owns the picture and/or where the picture is stored. The client must query the database to find out where the files are stored (the reason for this is that user pictures are added in arbitrary order, and they are often moved around). Lets say there are 1000 pictures, and I want to load them all into the browser (tiny thumbnails).
I could load up index.html then use Ajax to get all 1000 file locations and set populate the browser with images somewhat like so
for (var i = ; i < picturePaths.length ;i++){
var img = new Image();
img.src = picturePaths[i];
}
But I don’t want to use Ajax because it is very slow (3/4s) to kick in and retrieve any queries. Instead I want all the img.src attributes to already be set when the page loads.
Now John Watson mentioned below that I could/should return all of these in a single variable and reference that. I am not an expert so he could be right. However, My website is very complex, and different scripts are being dynamically loaded from the server quite frequently, I would prefer not to store important image path’s in a single global object.
My solution for this issue would be to separate my PHP and JavaScript where possible.
Let your PHP output whatever it needs to output into your HTML and then pick it up from your JavaScript if you want to use it. I can give you more concrete examples of this if you show us what you’re doing.
Dynamically spitting out a JavaScript file can be problematic as it will be cached on the browser, so the second and subsequent requests may not come back to the server to get a re-evaluated script file.