Search code examples
javascriptpythondjangodjango-pipelineyuglify

How to prevent name mangling of javascript functions in django-pipeline


I am using django version 1.82 with django-pipeline. I call a particular javascript function from html by name.

 <form class="navbar-form navbar-right vcenter" 
 action="javascript:search();" role="search" id='searchform'>

Unfortunately in the compressed js file, the name of the function is changed and hence the frontend functionality is not workig. How do I maintain the same name for that function or how do I change the reference to the js function in html?

I have installed yuglify and the settings I use is

PIPELINE_CSS = {
'allstyles': {
    'source_filenames': (
      'css/application.css',
      'feedback/css/feedback-form.css',
    ),
    'output_filename': 'css/nifty.css',
    'extra_context': {
        'media': 'screen,projection',
    },
},
}

PIPELINE_JS = {
'actions': {
    'source_filenames': (
      'js/nifty.js',
      'feedback/js/feedback-form.js',
    ),
    'output_filename': 'js/nifty.js',
}
}
STATICFILES_STORAGE = 'pipeline.storage.PipelineStorage'
PIPELINE_JS_COMPRESSOR = 'pipeline.compressors.yuglify.YuglifyCompressor'
PIPELINE_DISABLE_WRAPPER = True
PIPELINE_ENABLED=True 

Solution

  • Are you sure that search() is a global function? To make sure you can assign it to the window variable:

    window.search = function() {
        ...
    }