Jump to content

Can I minify javascript code that contains php?


Arbu

Recommended Posts

I've got a few bits of php in my javascript. I understand it's better to minify my code. But if I use a javascript minifier for the whole lot I get "// Error : Unexpected token: operator (<)" where the php is. So what to do? Should I minify the php and javascript separately? Could take quite a while to go through it all.

Thanks.

Link to comment
Share on other sites

If there is PHP embedded in your Javascript then I don't think it's worth minifying.

Ideally, you would completely separate Javascript and PHP and rewrite the code so that Javascript obtains the data through other means, such as HTML data attributes (generated by PHP) or AJAX.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...