Handling of JavaScript files in Sugar 7.7

Matthew Marum —  April 4, 2016 — 3 Comments

This post is a follow up on a question we posed on the Sugar Developer Community.

The “Rebuild Minified JS Files” action is used to rebuild the contents of the jssource directory.

pastedimage_0

We are considering removing this particular action from the UI because, generally, rebuilding the minfied JS files is not something we would expect most users to need to do.  While customizing jssource files is not upgrade safe, we recognize some folks in Sugar Developer community may be using this action for one reason or another.

Where is JavaScript stored in Sugar?

As of Sugar 7.7, the application stores JavaScript in multiple locations on the filesystem.

Core JavaScript files are stored in many places: under the include directory, the vendor directory, under many modules subdirectories, etc.  We also separately store Sidecar framework JavaScript files under the sidecar directory.

Copies of unminified core JavaScript source files have traditionally been placed under the jssource directory.

At runtime, core JavaScript files are minified and concatenated into groupings stored under the cache directory.  The contents of the JavaScript cache are regenerated as needed at runtime.

The Sugar application generally only uses the JavaScript stored in the cache directory at runtime. For example, a browser page running Sugar does not refer to any files under the jssource path.

In reality, there is no compelling need to store JavaScript files in three different locations. We need only one copy of unminified sources and one copy of minified sources located under the cache directory.

Keeping copies of unminified source files in a separate location under jssource is superfluous and increases confusion about how JavaScript files are handled.

Changes for Sugar 7.7 release

The following actions have been removed from the Sugar Administration user interface in Sugar 7.7.  They are available under the Repair panel.

  • Rebuild JS Compressed Files
  • Rebuild Minified JS Files
  • Repair JS Files

These three actions all rebuild core JavaScript files based upon contents of jssource directory.  This is not necessary when the JavaScript in the cache directory gets rebuilt during a Quick Repair or at runtime as needed.

While they have been removed from the UI, these actions still exist and have just been deprecated. You can still manually run these JavaScript actions if needed.

Manually running these actions

As an example, you can navigate to the following URL to run the Repair JS Files action from your browser.

http(s)://path_to_sugar/index.php?module=Administration&action=RepairJSFile&type=replace&run_deprecated_feature=1

You may need to update your config_override.php file to include additional http_referer configuration if you encounter a Cross Site Request Forgery (XSRF) warning.  Directions are included on that warning page if you encounter it.

For example, here is a config that will allow localhost to run the Repair JS Files action.

config_override.php

<?php
$sugar_config['http_referer']['list'][] = 'localhost';
$sugar_config['http_referer']['actions'] =array( 'index', 'ListView', 'DetailView', 'EditView', 'oauth', 'authorize', 'Authenticate', 'Login', 'SupportPortal', 'LogView', 'SugarpdfSettings', 'saveftsmodules', 'SaveSequence', 'PasswordManager', 'LicenseSettings', 'Updater', 'Backups', 'Languages', 'Locale', 'Upgrade', 'repair', 'GlobalSearchSettings', 'Diagnostic', 'EnableWirelessModules', 'ConfigureTabs', 'UpgradeWizard', 'ConfigureShortcutBar', 'wizard', 'historyContactsEmails', 'GoogleOauth2Redirect', 'RepairJSFile' ); 

If the action was run successfully, you should see the expected message.

Screen Shot 2016-03-30 at 5.17.23 PM

Repair JS Files message

 

Changes in upcoming Sugar releases

The jssource directory will be remove completely.  Unminified sources will still be available outside of the cache directory.  We also will then remove the code related to the deprecated JavaScript repair actions because at that time they would have use.

Matthew Marum

Posts

Matt is the Director of Developer Advocacy for SugarCRM. Previously he was an Engineer on Sugar 7 and a Solutions Architect for the OEM program. He is also an avid trail runner, Boston Marathon qualifier and a karaoke aficionado.

3 responses to Handling of JavaScript files in Sugar 7.7

  1. 

    Can SugarCRM generate map files for minified JS and CSS?

  2. 

    Hi,

    after switching to Chinese language, selected date not appearing in text box which is in jquery calendar. it shows empty.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s