Is there advantage to using Drupal.settings, as opposed to directly passing json-encoded var to javascript function Inside my custom views template, views-view-myview.tpl.php, I have a variable ("$myvar"), which I need to pass to a custom javascript function.  Here is how I am currently doing it:

A.  json-encode $myvar

&lt;?php
$my_json_var = json_encode($myvar);
?&gt;


B.  Pass the variable as an argument to my custom function, on page load

&lt;script&gt;
Drupal.behaviors.mystuff = function (context) {
  my_js_function(&lt;?php print $my_json_var; ?&gt;); 
});
&lt;/script&gt;


I am noticing that Drupal developers generally pass variables to javascript using Drupal.settings, and I am wondering whether I should switch and use Drupal.settings instead.

Question:
Is there any disadvantage of doing things my way, as described above?  Is there any reason it would be better to switch to Drupal.settings.
Note:  $myvar is relatively large, say 100k.

Thanks very much
The advantage of having in Drupal.settings is the values can be globally accessed across the JavaScript functions. In your case the function "my_js_function" only can access it because of its scope. It is based on the need and if you feel it is unnecessary to have it in settings then you can go with your method.

But best practice is to use Drupal settings. This method will never fail you.