We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Bug? Asset files incomplete on join or get ? characters appended at the end

I'm new to Phalcon but so far it's everything I could have asked for. I am, however, experiencing a strange and frustrating issue where my asset files either have strange characters at the end, or are incomplete when using

$assets->join(true)

This means javascript will report

Uncaught SyntaxError: Unexpected end of input 

e.g. /public/js/scripts.js

$(document).ready(function(){
    $('.datetimepicker').datetimepicker({
        format: 'yyyy-MM-dd hh:mm:ss',
        language: 'en'
    }); 
});�����������������������������������������������������
  • I have tried deleting and recreating the file.
  • I have tried different editors (Netbeans, Sublime, Vim).
  • I have tried restarting NGINX.
  • I have tried restarting my vagrant.

Any help/thoughts appreciated!



98.9k

If you're on a unix platform, try passing cat -v to the file to see any non-printable characters:

cat -v x.volt > new-x.volt


1.6k
edited Mar '14

Thanks, tried, but if I cat the file /var/www/public/js/scripts.js I see what I'd expect and want:

$(document).ready(function(){
    $('.datetimepicker input').datetimepicker({
        format: 'yyyy-MM-dd hh:mm:ss',
        language: 'en'
    });

    $('.btn-add').click(function(){
        console.log('btn-add');
    });
});

And if I navigate to https://localhost/js/scripts.js, I see some broken cached version:

$(document).ready(function(){
    $('.datetimepicker').datetimepicker({
        format: 'yyyy-MM-dd hh:mm:ss',
        language: 'en'
    }); 
});�����������������������������������������������������

I get the same broken file in different browsers.

Renaming the file to something new and loading that with $assets->addJs('new-scripts.js') does seem to fix the problem until I start making changes to the file, then same problem: changes stop showing and weird characters start appearing.



1.6k
Accepted
answer
edited Mar '14

Ok, so fleshing out the problem here made me think it must be NGINX, so googling the problem in that context got me to this handy link

https://jeremyfelt.com/code/2013/01/08/clear-nginx-cache-in-vagrant/

The solution is to open your NGINX config file and change to sendfile off: e.g. on my machine

$ sudo vim /etc/nginx/nginx.conf
sendfile off;
$ sudo service nginx restart
hard refresh browser